Skip to content

Commit

Permalink
replaces thrift collector with otlp collector (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
romank0 authored Jun 9, 2023
1 parent 82f5267 commit f6a954e
Show file tree
Hide file tree
Showing 4 changed files with 834 additions and 605 deletions.
32 changes: 5 additions & 27 deletions open_telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ For this sample, the optional `open_telemetry` dependency group must be included

poetry install --with open_telemetry

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

docker run -d --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 6831:6831/udp \
-p 4317:4317 \
-p 4318:4318 \
jaegertracing/all-in-one:latest

Since that is running in the background (`-d`), you can also run the metrics collector in the foreground:

docker run -p 4317:4317 \
-v /path/to/samples-python/open_telemetry/otel-metrics-collector-config.yaml:/etc/otel-collector-config.yaml \
otel/opentelemetry-collector:latest \
--config=/etc/otel-collector-config.yaml

Replace `/path/to/samples-python` with the absolute path to the cloned samples repo.

Now, from this directory, start the worker in its own terminal:

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

The metrics should have been dumped out in the terminal where the OpenTelemetry collector container is running.

## OTLP gRPC

Currently for tracing this example uses the `opentelemetry-exporter-jaeger-thrift` exporter because the common OTLP gRPC
exporter `opentelemetry-exporter-otlp-proto-grpc` uses an older, incompatible `protobuf` library. See
[this issue](https://github.com/open-telemetry/opentelemetry-python/issues/2880) for more information.

Once OTel supports latest protobuf, the exporter can be changed and Jaeger could be run with:

docker run -d --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
jaegertracing/all-in-one:latest
10 changes: 3 additions & 7 deletions open_telemetry/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

import opentelemetry.context
from opentelemetry import trace

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

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

# See https://github.com/temporalio/sdk-python/issues/199
opentelemetry.context.get_current()

# Connect client
client = await Client.connect(
"localhost:7233",
Expand Down
Loading

0 comments on commit f6a954e

Please sign in to comment.