You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/langsmith/trace-with-opentelemetry.mdx
+132-2Lines changed: 132 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -412,7 +412,7 @@ For exception events:
412
412
413
413
### Trace using the LangSmith SDK
414
414
415
-
Use the LangSmith SDK's OpenTelemetry helper to configure export:
415
+
Use the LangSmith SDK's OpenTelemetry helper to configure export. The following example [traces a Google ADK agent](/langsmith/trace-with-google-adk):
416
416
417
417
```python
418
418
import asyncio
@@ -454,7 +454,137 @@ if __name__ == "__main__":
454
454
You do not need to set OTEL environment variables or exporters. `configure()` wires them for LangSmith automatically; instrumentors (like `GoogleADKInstrumentor`) create the spans.
455
455
</Note>
456
456
457
-
5. View the trace in your LangSmith dashboard ([example](https://smith.langchain.com/public/106f5bed-edca-4357-91a5-80089252c9ed/r)).
457
+
Here is an [example](https://smith.langchain.com/public/d6d47eeb-511e-4fda-ad17-2caa7bd7150b/r) of what the resulting trace looks like in LangSmith.
458
+
459
+
### Add an attachment to a trace
460
+
461
+
LangSmith supports [attaching files to traces](/langsmith/upload-files-with-traces). This is useful when building an agent with multimodal inputs or outputs. Attachments are also supported when tracing with OpenTelemetry.
462
+
463
+
The example below [traces a Google ADK agent](/langsmith/trace-with-google-adk) and adds an attachment to the trace. It uses a combination of LangSmith's `OtelSpanProcessor` and a custom `AttachmentSpanProcessor` that uses [`on_end()`](https://opentelemetry-python.readthedocs.io/en/latest/sdk/trace.export.html#opentelemetry.sdk.trace.export.SimpleSpanProcessor.on_end) to add an image attachment to the parent span.
464
+
465
+
466
+
```python
467
+
import asyncio
468
+
import base64
469
+
import json
470
+
from pathlib import Path
471
+
from dotenv import load_dotenv
472
+
from google.adk import Runner
473
+
from google.adk.agents import LlmAgent
474
+
from google.adk.sessions import InMemorySessionService
475
+
from google.genai import types
476
+
from opentelemetry import trace
477
+
from opentelemetry.sdk.trace import TracerProvider, SpanProcessor
478
+
from langsmith.integrations.otel import OtelSpanProcessor
479
+
480
+
481
+
classAttachmentSpanProcessor(SpanProcessor):
482
+
"""Custom SpanProcessor to add attachments to invocation spans."""
483
+
484
+
def__init__(self):
485
+
self.attachment_data =None
486
+
487
+
defset_attachment(self, attachment_data):
488
+
self.attachment_data = attachment_data
489
+
490
+
defon_end(self, span):
491
+
if span.name =="invocation"andself.attachment_data:
0 commit comments