Skip to content

Commit b4b3b0c

Browse files
feat: add posthog.distinct_id and custom properties to OTel examples
1 parent b260273 commit b4b3b0c

38 files changed

Lines changed: 228 additions & 38 deletions

File tree

examples/example-ai-anthropic/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
1111
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
1212

13-
resource = Resource(attributes={SERVICE_NAME: "example-anthropic-app"})
13+
resource = Resource(attributes={
14+
SERVICE_NAME: "example-anthropic-app",
15+
"posthog.distinct_id": "example-user",
16+
"foo": "bar",
17+
"conversation_id": "abc-123",
18+
})
1419
exporter = OTLPSpanExporter(
1520
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",
1621
headers={"Authorization": f"Bearer {os.environ['POSTHOG_API_KEY']}"},

examples/example-ai-anthropic/extended_thinking.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
1212
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
1313

14-
resource = Resource(attributes={SERVICE_NAME: "example-anthropic-app"})
14+
resource = Resource(attributes={
15+
SERVICE_NAME: "example-anthropic-app",
16+
"posthog.distinct_id": "example-user",
17+
"foo": "bar",
18+
"conversation_id": "abc-123",
19+
})
1520
exporter = OTLPSpanExporter(
1621
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",
1722
headers={"Authorization": f"Bearer {os.environ['POSTHOG_API_KEY']}"},

examples/example-ai-anthropic/streaming.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
99
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
1010

11-
resource = Resource(attributes={SERVICE_NAME: "example-anthropic-app"})
11+
resource = Resource(attributes={
12+
SERVICE_NAME: "example-anthropic-app",
13+
"posthog.distinct_id": "example-user",
14+
"foo": "bar",
15+
"conversation_id": "abc-123",
16+
})
1217
exporter = OTLPSpanExporter(
1318
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",
1419
headers={"Authorization": f"Bearer {os.environ['POSTHOG_API_KEY']}"},

examples/example-ai-autogen/agent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
1010
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
1111

12-
resource = Resource(attributes={SERVICE_NAME: "example-autogen-app"})
12+
resource = Resource(attributes={
13+
SERVICE_NAME: "example-autogen-app",
14+
"posthog.distinct_id": "example-user",
15+
"foo": "bar",
16+
"conversation_id": "abc-123",
17+
})
1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",
1520
headers={"Authorization": f"Bearer {os.environ['POSTHOG_API_KEY']}"},

examples/example-ai-aws-bedrock/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
1010
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
1111

12-
resource = Resource(attributes={SERVICE_NAME: "example-bedrock-app"})
12+
resource = Resource(attributes={
13+
SERVICE_NAME: "example-bedrock-app",
14+
"posthog.distinct_id": "example-user",
15+
"foo": "bar",
16+
"conversation_id": "abc-123",
17+
})
1318

1419
exporter = OTLPSpanExporter(
1520
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",

examples/example-ai-azure-openai/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from opentelemetry.sdk.trace import TracerProvider
1010
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
1111

12-
resource = Resource(attributes={SERVICE_NAME: "example-azure-openai-app"})
12+
resource = Resource(attributes={
13+
SERVICE_NAME: "example-azure-openai-app",
14+
"posthog.distinct_id": "example-user",
15+
"foo": "bar",
16+
"conversation_id": "abc-123",
17+
})
1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",
1520
headers={"Authorization": f"Bearer {os.environ['POSTHOG_API_KEY']}"},

examples/example-ai-cerebras/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
99
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
1010

11-
resource = Resource(attributes={SERVICE_NAME: "example-cerebras-app"})
11+
resource = Resource(attributes={
12+
SERVICE_NAME: "example-cerebras-app",
13+
"posthog.distinct_id": "example-user",
14+
"foo": "bar",
15+
"conversation_id": "abc-123",
16+
})
1217

1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",

examples/example-ai-cohere/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
99
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
1010

11-
resource = Resource(attributes={SERVICE_NAME: "example-cohere-app"})
11+
resource = Resource(attributes={
12+
SERVICE_NAME: "example-cohere-app",
13+
"posthog.distinct_id": "example-user",
14+
"foo": "bar",
15+
"conversation_id": "abc-123",
16+
})
1217

1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",

examples/example-ai-deepseek/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
99
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
1010

11-
resource = Resource(attributes={SERVICE_NAME: "example-deepseek-app"})
11+
resource = Resource(attributes={
12+
SERVICE_NAME: "example-deepseek-app",
13+
"posthog.distinct_id": "example-user",
14+
"foo": "bar",
15+
"conversation_id": "abc-123",
16+
})
1217

1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",

examples/example-ai-fireworks-ai/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
99
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
1010

11-
resource = Resource(attributes={SERVICE_NAME: "example-fireworks-ai-app"})
11+
resource = Resource(attributes={
12+
SERVICE_NAME: "example-fireworks-ai-app",
13+
"posthog.distinct_id": "example-user",
14+
"foo": "bar",
15+
"conversation_id": "abc-123",
16+
})
1217

1318
exporter = OTLPSpanExporter(
1419
endpoint=f"{os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')}/i/v0/ai/otel",

0 commit comments

Comments
 (0)