Skip to content

fix(runtime-sdk): fix top-level import for opentelemetry package - #248

Open
ryanking13 wants to merge 2 commits into
mainfrom
gyeongjae/opentelemetry
Open

fix(runtime-sdk): fix top-level import for opentelemetry package#248
ryanking13 wants to merge 2 commits into
mainfrom
gyeongjae/opentelemetry

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

opentelementry is used inside the official mcp and fastMCP package, and has os.urandom() calls during the initialization

@ryanking13 ryanking13 changed the title fix(runtime-sdk): add entropy patch for opentelemetry fix(runtime-sdk): fix top-level import for opentelemetry package Sep 8, 2026
Comment thread packages/runtime-sdk/src/_workers_sdk_entropy_import_context.py
@ask-bonk

ask-bonk Bot commented Sep 8, 2026

Copy link
Copy Markdown

I'm Bonk, and I've done a quick review of your PR.

PR #248 adds an entropy allowance for OpenTelemetry context imports.

  1. High: opentelemetry.trace still triggers an unallowed UUID entropy call via opentelemetry.trace.propagation, the path used by MCP and FastMCP. Posted 2 inline suggestions.

github run

@ryanking13

Copy link
Copy Markdown
Contributor Author

@ask-bonk try again

@contextmanager
def opentelemetry_context(module):
# OpenTelemetry creates three UUID-backed context keys at import time.
with allow_bad_entropy_calls(3):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow_bad_entropy_calls() requires the exact count to be consumed. opentelemetry-api 1.28.0 through 1.39.1 create only two context keys; the third key was added in 1.40.0, while MCP and FastMCP accept opentelemetry-api>=1.28.0. Those valid resolutions therefore raise 1 unexpected leftover getentropy calls here. Make the allowance version-compatible (or constrain the supported version) and cover both the minimum and current API versions.

@@ -0,0 +1,8 @@
# ruff: noqa: F401
import opentelemetry.context
import opentelemetry.trace

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding opentelemetry.trace covers the previously reported span key, but MCP and FastMCP also import opentelemetry.propagate. Its default baggage propagator imports opentelemetry.baggage, where _BAGGAGE_KEY = create_key("baggage") runs after both new patch contexts have exited, so import mcp still performs an unallowed entropy call. Patch opentelemetry.baggage and exercise opentelemetry.propagate or the actual MCP entry point here.

# "langchain-openai",
# "openai",
"litestar",
"opentelemetry-sdk",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency only tests OpenTelemetry itself, so it misses another top-level call in the stated FastMCP consumer. FastMCP 4.0.3 executes _SUPPRESS_KEY = otel_context.create_key("fastmcp_suppress_telemetry") in fastmcp.telemetry after the OpenTelemetry imports complete. Even after covering baggage, from fastmcp import FastMCP remains blocked; add a patch and an import test for FastMCP, or use a general snapshot-safe create_key solution.

@ask-bonk

ask-bonk Bot commented Sep 8, 2026

Copy link
Copy Markdown

Posted 3 new inline findings.

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant