Skip to content

Commit 8f28e2a

Browse files
authored
[Monitor exporter] Add OTLP and dual exporter scenario to samples (#20634)
* rpc * samples
1 parent 5450368 commit 8f28e2a

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ These code samples show common champion scenario operations with the AzureMonito
1414
* Azure Service Bus Receive: [sample_servicebus_receive.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_servicebus_receive.py)
1515
* Azure Storage Blob Create Container: [sample_storage.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_storage.py)
1616
* Client: [sample_client.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_client.py)
17+
* Jaeger: [sample_jaeger.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_jaeger.py)
1718
* Trace: [sample_trace.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_trace.py)
1819
* Server: [sample_server.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_server.py)
1920

@@ -63,6 +64,60 @@ $ python sample_server.py
6364

6465
* Open http://localhost:8080/
6566

67+
### Jaeger
68+
69+
* The Jaeger project provides an all-in-one Docker container with a UI, database, and consumer. Run the following command to start Jaeger:
70+
71+
```sh
72+
$ docker run -p 16686:16686 -p 6831:6831/udp jaegertracing/all-in-one
73+
```
74+
75+
* This command starts Jaeger locally on port 16686 and exposes the Jaeger thrift agent on port 6831. You can visit Jaeger at http://localhost:16686.
76+
77+
* Install the OpenTelemetry Jaeger Exporter
78+
79+
```sh
80+
$ pip install opentelemetry-exporter-jaeger
81+
```
82+
83+
* Update `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable
84+
85+
* Run the sample
86+
87+
```sh
88+
$ # from this directory
89+
$ python sample_jaeger.py
90+
```
91+
92+
* You should be able to see your traces in the Jaeger backend as well as Azure Monitor application insights backend.
93+
94+
### Collector
95+
96+
* Start the Collector locally to see how the Collector works in practice.
97+
98+
* From the same folder as collector/otel-collector-config.yaml and collector/docker-compose.yml, start the Docker container.
99+
100+
```sh
101+
$ docker-compose up
102+
```
103+
104+
* Install the OpenTelemetry OTLP Exporter
105+
106+
```sh
107+
$ pip install opentelemetry-exporter-otlp
108+
```
109+
110+
* Update `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable
111+
112+
* Run the sample
113+
114+
```sh
115+
# from collector directory
116+
$ python sample_collector.py
117+
```
118+
119+
* You should be able to see your traces in the Zipkin backend as well as Azure Monitor application insights backend.
120+
66121
### Azure Service Bus Send
67122

68123
The following sample assumes that you have setup an Azure Service Bus [namespace](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-quickstart-portal).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "2"
2+
services:
3+
4+
# Zipkin
5+
zipkin-all-in-one:
6+
image: openzipkin/zipkin:latest
7+
ports:
8+
- "9411:9411"
9+
10+
otel-collector:
11+
image: otel/opentelemetry-collector:latest
12+
command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"]
13+
volumes:
14+
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
15+
ports:
16+
- "4317:4317" # OTLP gRPC receiver
17+
depends_on:
18+
- zipkin-all-in-one
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
http:
6+
exporters:
7+
logging:
8+
loglevel: debug
9+
10+
zipkin:
11+
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
12+
format: proto
13+
14+
processors:
15+
batch:
16+
service:
17+
pipelines:
18+
traces:
19+
receivers: [otlp]
20+
exporters: [logging, zipkin]
21+
processors: [batch]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""
4+
An example to show an application using Opentelemetry tracing api and sdk with the OpenTelemetry Collector
5+
and the Azure monitor exporter.
6+
Telemetry is exported to application insights with the AzureMonitorTraceExporter and Zipkin with the
7+
OTLP Span exporter.
8+
"""
9+
import os
10+
from opentelemetry import trace
11+
12+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
13+
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
14+
from opentelemetry.sdk.trace import TracerProvider
15+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
16+
17+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
18+
19+
trace.set_tracer_provider(
20+
TracerProvider(
21+
resource=Resource.create({SERVICE_NAME: "my-zipkin-service"})
22+
)
23+
)
24+
tracer = trace.get_tracer(__name__)
25+
26+
exporter = AzureMonitorTraceExporter.from_connection_string(
27+
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
28+
)
29+
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317")
30+
span_processor = BatchSpanProcessor(otlp_exporter)
31+
trace.get_tracer_provider().add_span_processor(span_processor)
32+
33+
with tracer.start_as_current_span("test"):
34+
print("Hello world!")
35+
input(...)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
"""
4+
An example to show an application using Opentelemetry tracing api and sdk with multiple exporters.
5+
Telemetry is exported to application insights with the AzureMonitorTraceExporter and Jaeger backend with the JaegerExporter.
6+
"""
7+
import os
8+
from opentelemetry import trace
9+
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
10+
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
11+
from opentelemetry.sdk.trace import TracerProvider
12+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
13+
14+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
15+
16+
17+
exporter = AzureMonitorTraceExporter.from_connection_string(
18+
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
19+
)
20+
21+
jaeger_exporter = JaegerExporter(
22+
agent_host_name="localhost",
23+
agent_port=6831,
24+
)
25+
26+
# Service name needs to be populated for Jaeger to see traces
27+
trace.set_tracer_provider(
28+
TracerProvider(
29+
resource=Resource.create({SERVICE_NAME: "my-jaeger-service"})
30+
)
31+
)
32+
tracer = trace.get_tracer(__name__)
33+
span_processor = BatchSpanProcessor(exporter)
34+
trace.get_tracer_provider().add_span_processor(span_processor)
35+
36+
with tracer.start_as_current_span("hello"):
37+
print("Hello, World!")

0 commit comments

Comments
 (0)