Skip to content

Commit 5f21a72

Browse files
committed
feat(otlp): Add python OTLP example
1 parent f06a280 commit 5f21a72

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/concepts/otlp/index.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exporters:
4949
5050
### Using an OpenTelemetry SDK
5151
52-
You can configure the OpenTelemetry Exporter directly in your application code. Here is an example with the OpenTelemetry Node SDK:
52+
You can configure the OpenTelemetry Exporter directly in your application code. Here are examples with the OpenTelemetry Node and Python SDKs:
5353
5454
```typescript {filename: app.ts}
5555
import { NodeSDK } from "@opentelemetry/sdk-node";
@@ -67,6 +67,37 @@ const sdk = new NodeSDK({
6767
sdk.start();
6868
```
6969

70+
```python {filename: app.py}
71+
import sentry_sdk
72+
from sentry_sdk.integrations.otlp import OtlpIntegration
73+
from opentelemetry import trace
74+
from opentelemetry.sdk.trace import TracerProvider
75+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
76+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
77+
78+
# Initialize OpenTelemetry
79+
trace.set_tracer_provider(TracerProvider())
80+
81+
otlp_exporter = OTLPSpanExporter(
82+
endpoint="___OTLP_TRACES_URL___",
83+
headers={"x-sentry-auth": "sentry sentry_key=___PUBLIC_KEY___"},
84+
)
85+
span_processor = BatchSpanProcessor(otlp_exporter)
86+
trace.get_tracer_provider().add_span_processor(span_processor)
87+
88+
sentry_sdk.init(integrations=[OtlpIntegration()])
89+
```
90+
91+
You can find the values of Sentry's OTLP traces endpoint and public key in your Sentry project settings.
92+
93+
1. Go to the [Settings > Projects](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/) page in Sentry.
94+
2. Select a project from the list.
95+
3. Go to the "Client Keys (DSN)" sub-page for this project under the "SDK Setup" heading.
96+
97+
### Linking Errors with Traces
98+
99+
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.
100+
70101
## OpenTelemetry Logs
71102

72103
<Include name="feature-available-open-beta-logs.mdx" />

0 commit comments

Comments
 (0)