Skip to content

Commit a3a3464

Browse files
committed
feat(otlp): Add python OTLP example
1 parent 38382a6 commit a3a3464

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docs/concepts/otlp/index.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="___OTLP_TRACES_URL___"
2424
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___"
2525
```
2626

27-
Alternatively, you can configure the OpenTelemetry Exporter directly in your application code. Here is an example with the OpenTelemetry Node SDK:
27+
Alternatively, you can configure the OpenTelemetry Exporter directly in your application code. Here are examples with the OpenTelemetry Node and Python SDKs:
2828

2929
```typescript {filename: app.ts}
3030
import { NodeSDK } from "@opentelemetry/sdk-node";
@@ -42,12 +42,37 @@ const sdk = new NodeSDK({
4242
sdk.start();
4343
```
4444

45+
```python {filename: app.py}
46+
import sentry_sdk
47+
from sentry_sdk.integrations.otlp import OtlpIntegration
48+
from opentelemetry import trace
49+
from opentelemetry.sdk.trace import TracerProvider
50+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
51+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
52+
53+
# Initialize OpenTelemetry
54+
trace.set_tracer_provider(TracerProvider())
55+
56+
otlp_exporter = OTLPSpanExporter(
57+
endpoint="___OTLP_TRACES_URL___",
58+
headers={"x-sentry-auth": "sentry sentry_key=___PUBLIC_KEY___"},
59+
)
60+
span_processor = BatchSpanProcessor(otlp_exporter)
61+
trace.get_tracer_provider().add_span_processor(span_processor)
62+
63+
sentry_sdk.init(integrations=[OtlpIntegration()])
64+
```
65+
4566
You can find the values of Sentry's OTLP traces endpoint and public key in your Sentry project settings.
4667

4768
1. Go to the [Settings > Projects](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/) page in Sentry.
4869
2. Select a project from the list.
4970
3. Go to the "Client Keys (DSN)" sub-page for this project under the "SDK Setup" heading.
5071

72+
### Linking Errors with Traces
73+
74+
For Python, make sure to enable the `OtlpIntegration` for the Sentry SDK so that other event types such as Errors and Logs are connected to the correct Trace.
75+
5176
## OpenTelemetry Logs
5277

5378
<Include name="feature-available-ea-logs.mdx" />

0 commit comments

Comments
 (0)