{"id":4156,"library":"opentelemetry-instrumentation-writer","title":"OpenTelemetry Writer Instrumentation for Traceloop SDK","description":"This package provides OpenTelemetry instrumentation for the internal `writer` module within the Traceloop SDK. It helps capture tracing data related to text generation and other 'write' operations performed by the `traceloop-sdk`. It's part of the broader OpenLLMetry project, focusing on observability for LLM applications. Releases are frequent, often several times a week, aligning with the rapid development of the OpenLLMetry ecosystem.","status":"active","version":"0.58.0","language":"en","source_language":"en","source_url":"https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-writer","tags":["opentelemetry","instrumentation","ai","llm","genai","observability","tracing","traceloop"],"install":[{"cmd":"pip install opentelemetry-instrumentation-writer","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Core OpenTelemetry API for defining traces.","package":"opentelemetry-api"},{"reason":"Core OpenTelemetry SDK for trace implementation.","package":"opentelemetry-sdk"},{"reason":"Used for robust monkey patching to instrument target libraries.","package":"wrapt"},{"reason":"This instrumentation targets an internal component of `traceloop-sdk`. It is required for any traces to be generated.","package":"traceloop-sdk"}],"imports":[{"symbol":"WriterInstrumentor","correct":"from opentelemetry.instrumentation.writer import WriterInstrumentor"}],"quickstart":{"code":"from opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\n\n# NOTE: This instrumentation requires 'traceloop-sdk' to be installed\n# and its internal 'writer' components to be used to generate traces.\n# You would typically install it via `pip install traceloop-sdk`.\n\n# Optional: Also install a specific LLM library like openai, anthropic, etc.\n# e.g., pip install opentelemetry-instrumentation-openai\n\n# 1. Import the specific instrumentation\nfrom opentelemetry.instrumentation.writer import WriterInstrumentor\n\n# 2. Set up a basic OpenTelemetry TracerProvider and Exporter\nresource = Resource.create({\"service.name\": \"my-traceloop-writer-app\"})\nprovider = TracerProvider(resource=resource)\nprocessor = SimpleSpanProcessor(ConsoleSpanExporter())\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\n# 3. Instrument the target library\nWriterInstrumentor().instrument()\n\n# 4. Now, if `traceloop-sdk` is used, operations involving its internal\n#    'writer' module (e.g., handling LLM inputs/outputs) will generate spans.\n#    For example, if you were using `traceloop-sdk` to wrap an OpenAI call:\n#\n# from traceloop.sdk import Traceloop\n# from openai import OpenAI\n# Traceloop.init(app_name=\"my-llm-app\", disable_batch=True) # Enables ALL Traceloop instrumentations\n# client = OpenAI()\n# response = client.chat.completions.create(\n#    model=\"gpt-3.5-turbo\", messages=[{\"role\": \"user\", \"content\": \"Hello\"}]\n# )\n# print(response.choices[0].message.content)\n\nprint(\"OpenTelemetry Writer Instrumentation enabled. Traces will appear when traceloop-sdk 'writer' module is invoked.\")\n","lang":"python","description":"This quickstart demonstrates how to manually initialize OpenTelemetry, enable the `WriterInstrumentor`, and explains that traces will be generated when the `traceloop-sdk`'s internal `writer` module is used. This instrumentation is typically part of the broader `Traceloop.init()` setup, but can be enabled standalone."},"warnings":[{"fix":"Ensure `traceloop-sdk` is installed (`pip install traceloop-sdk`) and integrated into your LLM application for this instrumentation to have an effect.","message":"This instrumentation package explicitly depends on and instruments components of the `traceloop-sdk`. Installing `opentelemetry-instrumentation-writer` alone will not generate any traces unless `traceloop-sdk` is also installed and actively used within your application.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly consult the OpenTelemetry GenAI Semantic Conventions documentation and the `openllmetry` release notes. Update your trace consumers and dashboards to reflect the latest attribute specifications.","message":"The OpenTelemetry Generative AI Semantic Conventions are evolving rapidly. This means that span attribute names, types, and structures emitted by this instrumentation can change frequently between minor and even patch versions, requiring updates to any custom trace processing or analysis logic.","severity":"breaking","affected_versions":"0.53.0 and newer (and likely future versions)"},{"fix":"Understand that this instrumentation operates at a low level within the `traceloop-sdk`. To see its effects, integrate and use `traceloop-sdk` as documented, and observe the resulting spans rather than trying to directly invoke the `WriterModule`.","message":"The `WriterInstrumentor` targets `traceloop.sdk.tracing.writer.WriterModule`, which is an internal component of `traceloop-sdk`. Users typically do not directly interact with `WriterModule`. Traces are generated implicitly when using `traceloop-sdk`'s higher-level functionalities, such as LLM wrappers or agents.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}