Skip to content

Commit f6a954e

Browse files
authored
replaces thrift collector with otlp collector (temporalio#73)
1 parent 82f5267 commit f6a954e

4 files changed

Lines changed: 834 additions & 605 deletions

File tree

open_telemetry/README.md

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@ For this sample, the optional `open_telemetry` dependency group must be included
66

77
poetry install --with open_telemetry
88

9-
To run, first see [README.md](../README.md) for prerequisites. Then run the following to start a Jaeger container to
10-
view the trace results:
9+
To run, first see [README.md](../README.md) for prerequisites. Then run the following to start a Jaeger container
10+
with OTLP collector enabled to collect and view the trace results:
1111

1212
docker run -d --name jaeger \
13+
-e COLLECTOR_OTLP_ENABLED=true \
1314
-p 16686:16686 \
14-
-p 6831:6831/udp \
15+
-p 4317:4317 \
16+
-p 4318:4318 \
1517
jaegertracing/all-in-one:latest
1618

17-
Since that is running in the background (`-d`), you can also run the metrics collector in the foreground:
18-
19-
docker run -p 4317:4317 \
20-
-v /path/to/samples-python/open_telemetry/otel-metrics-collector-config.yaml:/etc/otel-collector-config.yaml \
21-
otel/opentelemetry-collector:latest \
22-
--config=/etc/otel-collector-config.yaml
23-
24-
Replace `/path/to/samples-python` with the absolute path to the cloned samples repo.
25-
2619
Now, from this directory, start the worker in its own terminal:
2720

2821
poetry run python worker.py
@@ -43,18 +36,3 @@ Therefore we intentionally start-then-end in-workflow spans immediately. So whil
4336
accurate, the duration is not.
4437

4538
The metrics should have been dumped out in the terminal where the OpenTelemetry collector container is running.
46-
47-
## OTLP gRPC
48-
49-
Currently for tracing this example uses the `opentelemetry-exporter-jaeger-thrift` exporter because the common OTLP gRPC
50-
exporter `opentelemetry-exporter-otlp-proto-grpc` uses an older, incompatible `protobuf` library. See
51-
[this issue](https://github.com/open-telemetry/opentelemetry-python/issues/2880) for more information.
52-
53-
Once OTel supports latest protobuf, the exporter can be changed and Jaeger could be run with:
54-
55-
docker run -d --name jaeger \
56-
-e COLLECTOR_OTLP_ENABLED=true \
57-
-p 16686:16686 \
58-
-p 4317:4317 \
59-
-p 4318:4318 \
60-
jaegertracing/all-in-one:latest

open_telemetry/worker.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
import opentelemetry.context
55
from opentelemetry import trace
6-
7-
# See note in README about why Thrift
8-
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
6+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
97
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
108
from opentelemetry.sdk.trace import TracerProvider
119
from opentelemetry.sdk.trace.export import BatchSpanProcessor
@@ -38,7 +36,8 @@ async def compose_greeting(name: str) -> str:
3836
def init_runtime_with_telemetry() -> Runtime:
3937
# Setup global tracer for workflow traces
4038
provider = TracerProvider(resource=Resource.create({SERVICE_NAME: "my-service"}))
41-
provider.add_span_processor(BatchSpanProcessor(JaegerExporter()))
39+
exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)
40+
provider.add_span_processor(BatchSpanProcessor(exporter))
4241
trace.set_tracer_provider(provider)
4342

4443
# Setup SDK metrics to OTel endpoint
@@ -52,9 +51,6 @@ def init_runtime_with_telemetry() -> Runtime:
5251
async def main():
5352
runtime = init_runtime_with_telemetry()
5453

55-
# See https://github.com/temporalio/sdk-python/issues/199
56-
opentelemetry.context.get_current()
57-
5854
# Connect client
5955
client = await Client.connect(
6056
"localhost:7233",

0 commit comments

Comments
 (0)