Before you can view the trace data of your application in the Tracing Analysis console, you must use a client to report the trace data to Tracing Analysis. This topic describes how to use Jaeger to report Python application data.
Prerequisites
- Log on to the Tracing Analysis console. In the left-side navigation pane, click Cluster Configurations.
- On the Cluster Configurations tab, click the Access point information tab. Then, turn on Show Token for the Cluster Information parameter.
- Set the Client parameter to the client that you want to use to collect trace data.
- In the Related Information column of the table in the lower part, click the copy icon next to the endpoint that you want to use.
Note: If you deploy your application in an Alibaba Cloud production environment, select a Virtual Private Cloud (VPC) endpoint. Otherwise, select a public endpoint. Generally, use the endpoint of v2 for Zipkin. Use the endpoint of v1 only if you know Zipkin well.
Background information
The following figure shows how to report data without using the Jaeger agent.
The following figure shows how to report data by using the Jaeger agent.
Precautions
- For Python, Jaeger v1.25 allows you to report trace data only by using the Jaeger agent. You cannot report trace data over HTTP. For more information, see Jaeger documentation.
- For Python, Jaeger v1.25 allows you to report trace data from the Jaeger client to the Jaeger agent only over UDP. The UDP protocol does not guarantee the reliability of communication. To ensure reliable transfer of trace data, we recommend that you run the Jaeger client and the Jaeger agent on the same host.
Step 1: Build an environment
This section lists the versions that are required for Docker, the Jaeger agent, the Jaeger client, and Python.
Docker and the Jaeger agent
Docker version: 20.10.7
Jaeger agent version: 1.25
- Run the following command in Docker Hub to pull the image of the Jaeger agent v1.25:
docker pull jaegertracing/jaeger-agent:1.25
- Run the following command to run the Jaeger agent v1.25:
docker run -d --name jaeger-agent -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778/tcp jaegertracing/jaeger-agent:1.25 --reporter.type=grpc --reporter.grpc.host-port=<endpoint>(Enter the endpoint) --agent.tags=<auth>(Enter the authentication information)
Note Replace<endpoint>
and<auth>
with the information displayed on the Cluster Configurations page of the Tracing Analysis console. For more information about how to obtain the endpoint, see the Prerequisites section in this topic.
Python and the Jaeger client
Python version: 3.8.5
Jaeger client version: 4.6.0
Install the following Python package in Python to configure the Jaeger client environment.
certifi==2021.5.30
charset-normalizer==2.0.4
idna==3.2
jaeger-client==4.6.0
opentracing==2.4.0
requests==2.26.0
six==1.16.0
threadloop==1.0.2
thrift==0.13.0
tornado==6.1
urllib3==1.26.6
Step 2: Create a Tracer object
View data in the Tracing Analysis console
References
This section provides common methods for using Jaeger. For more information, see Jaeger documentation.
- Create a Tracer object.
from jaeger_client import Config def init_jaeger_tracer(service_name='your-app-name'): config = Config(config={}, service_name=service_name) return config.initialize_tracer()
- Create and finish a span.
// Start a span that does not have a parent span. tracer.start_span('TestSpan') // Start a span that has a parent span. tracer.start_span('ChildSpan', child_of=span) // Finish the span. span.finish()
- Pass a SpanContext.
// Serialization: Inject a SpanContext and pass it to the next span. tracer.inject( span_context=span.context, format=Format.TEXT_MAP, carrier=carrier ) // Deserialization: Extract a SpanContext that is passed. span_ctx = tracer.extract(format=Format.TEXT_MAP, carrier={})