ObserveNow
...
Integrations
Applications

Python

Instrumenting your app

Please follow the steps outlined in this document.

Setting the POD annotations

Once your application is emitting metrics, your POD in K8s will need to be annotated to enable the agent to scrape the metrics. Following are the relevant annotations:

YAML


Trace context (TraceId, SpanId and TraceFlags) injection into logs

It is very simple to configure trace context (traceId, spanId, and trace flags) injection into user logs in Python applications. Please follow the below mentioned steps to inject the trace context to the logs:

There is no out of the box auto-instrumentation to inject the trace context. Instead, you'll have to get a context from current span and attach it to the log statement.

Step 1: Import the library.

Python


Step 2: Get the current span context.

Python


Step 3: Get trace_id and span_id from the context.

Python


Step 4: Inject trace context (trace_id and span_id) to the log.

Python


Please ensure the aforementioned code block is added to a file where your application requests are traced with OTel Python instrumentation.

Single Machine

If you are running a python application in a VM, ensure you have installed OpsVerse Agent and OpenTelemetry Collector using steps in the OpsVerse Docs, and then instrument your application using the docs below: