Skip to content

🐛 Bug Report: Missing warning message when no instrumentors are initialized #3042

Closed
@ronensc

Description

@ronensc

Which component is this bug for?

Traceloop SDK

📜 Description

When no instrumentors are initialized via Traceloop.init(), no warning message is emitted.
This makes it harder to detect misconfiguration or missing dependencies.

👟 Reproduction steps

  1. Create a fresh virtual environment.

  2. Install the SDK (and no other LLM/framework package):

pip install traceloop-sdk==0.40.12  
  1. Run the following code:
from traceloop.sdk import Traceloop
from traceloop.sdk.instruments import Instruments

Traceloop.init(instruments={Instruments.MCP})
  1. Observe that no warning is printed, even though no instrumentors are active.

👍 Expected behavior

A warning message should be emitted when no instrumentors are initialized, e.g.:

Warning: No valid instruments set. 

👎 Actual Behavior with Screenshots

none

🤖 Python Version

No response

📃 Provide any additional context for the Bug.

It appears that the issue stems from the init_<x>_instrumentor() functions returning True even when no instrumentation actually occurs — for example, when the corresponding package is not installed.

Here’s an example from init_mcp_instrumentor():

def init_mcp_instrumentor():
try:
if is_package_installed("mcp"):
Telemetry().capture("instrumentation:mcp:init")
from opentelemetry.instrumentation.mcp import McpInstrumentor
instrumentor = McpInstrumentor(
exception_logger=lambda e: Telemetry().log_exception(e),
)
if not instrumentor.is_instrumented_by_opentelemetry:
instrumentor.instrument()
return True
except Exception as e:
logging.error(f"Error initializing MCP instrumentor: {e}")
Telemetry().log_exception(e)
return False

There's an easy fix to apply to all instrumentors - move the return True statement inside the if is_package_installed() block to avoid false positives:

def init_mcp_instrumentor():
    try:
        if is_package_installed("mcp"):
            Telemetry().capture("instrumentation:mcp:init")
            from opentelemetry.instrumentation.mcp import McpInstrumentor

            instrumentor = McpInstrumentor(
                exception_logger=lambda e: Telemetry().log_exception(e),
            )
            if not instrumentor.is_instrumented_by_opentelemetry:
                instrumentor.instrument()
            return True
    except Exception as e:
        logging.error(f"Error initializing MCP instrumentor: {e}")
        Telemetry().log_exception(e)
    return False

This pattern should be applied to all instrumentor init functions.

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions