How to set tags for spans #2769
saritatewari4
started this conversation in
General
Replies: 1 comment
-
Please format the question properly. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all, I am instrumenting open telemetry with python. I am using baggage for sending extra fields while propagating. I want to set the baggage key as a tag key so that I can search in jaeger ui on the basis of tag. Please help, how I can configure it. This is my code:
`from opentelemetry import trace, baggage
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
OTLPSpanExporter,
)
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace import TracerProvider
def hello(**kwargs):
span_exporter = OTLPSpanExporter(
)
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
span_processor = SimpleSpanProcessor(span_exporter)
tracer_provider.add_span_processor(span_processor)
Configure the tracer to use the collector exporter
tracer = trace.get_tracer_provider().get_tracer(name)
with tracer.start_span(name="root span" ) as root_span:
ctx = baggage.set_baggage("foo", "bar")
print(f"Global context baggage: {baggage.get_all()}")
print(f"Span context baggage: {baggage.get_all(context=ctx)}")
with tracer.start_as_current_span(name="root span") as root_span:
parent_ctx = baggage.set_baggage("context", "parent")
with tracer.start_as_current_span(
name="child span", context=parent_ctx
) as child_span:
child_ctx = baggage.set_baggage("context", "child")
print(baggage.get_baggage("context", parent_ctx))
print(baggage.get_baggage("context", child_ctx))
`
And this is my docker compose file:
version: "3" services: jaeger: image: jaegertracing/all-in-one:latest networks: - otelcol ports: - "16686:16686" - "14250" zipkin: image: openzipkin/zipkin-slim:latest networks: - otelcol hostname: zipkin ports: - "9412:9411" collector: image: otel/opentelemetry-collector-contrib:0.42.0 networks: - otelcol command: [ "--config=/otel-config.yaml" ] volumes: - ./otel-config.yaml:/otel-config.yaml hostname: collector ports: - "4317:4317" - "55680:55680" - "9411:9411" depends_on: - jaeger - zipkin networks: otelcol:
Check otel-config.yaml file:
extensions: health_check: {} receivers: otlp: protocols: grpc: zipkin: exporters: jaeger: endpoint: jaeger:14250 tls: insecure: true zipkin: endpoint: "http://zipkin:9411/api/v2/spans" logging: loglevel: debug service: pipelines: traces: receivers: [ otlp,zipkin ] exporters: [ jaeger,zipkin,logging ]
Beta Was this translation helpful? Give feedback.
All reactions