Instrument Python application for OpenTelemetry
To monitor your Python application with Site24x7 OpenTelemetry, follow the steps below.
Step 1:
Install the required modules.
pip install opentelemetry-api
pip install opentelemetry-exporter-otlp
Add the following lines to your application's main file.
from opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProvider
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor
endpointurl = 'https://otel.site24x7rum.com:4318/v1/traces', // url is optional and can be omitted - default is http://localhost:4318/v1/traces
endpointheaders = { 'api-key': <license.key>}
// you can set directly the endpoint url by the below step
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint = endpointurl, headers = endpointheaders)))
Step 2: Run the application
Start your application server or follow the steps below.
- Set the endpoint URL and headers.
export OTEL_EXPORTER_OTLP_ENDPOINT: "endpoint url"
export OTEL_EXPORTER_OTLP_HEADERS:"api-key=<license-key>" - Add the following lines to your application's main file and start your server.
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor
Note
To know more about the OpenTelemetry instrumentation steps for Python applications, click here.
You are all set. Now the agent will start sending the performance metrics to your Site24x7 web client portal.