forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Monitor exporter] Add OTLP and dual exporter scenario to samples (Az…
…ure#20634) * rpc * samples
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/collector/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "2" | ||
services: | ||
|
||
# Zipkin | ||
zipkin-all-in-one: | ||
image: openzipkin/zipkin:latest | ||
ports: | ||
- "9411:9411" | ||
|
||
otel-collector: | ||
image: otel/opentelemetry-collector:latest | ||
command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] | ||
volumes: | ||
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml | ||
ports: | ||
- "4317:4317" # OTLP gRPC receiver | ||
depends_on: | ||
- zipkin-all-in-one |
21 changes: 21 additions & 0 deletions
21
.../azure-monitor-opentelemetry-exporter/samples/traces/collector/otel-collector-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
exporters: | ||
logging: | ||
loglevel: debug | ||
|
||
zipkin: | ||
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans" | ||
format: proto | ||
|
||
processors: | ||
batch: | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
exporters: [logging, zipkin] | ||
processors: [batch] |
35 changes: 35 additions & 0 deletions
35
...monitor/azure-monitor-opentelemetry-exporter/samples/traces/collector/sample_collector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
""" | ||
An example to show an application using Opentelemetry tracing api and sdk with the OpenTelemetry Collector | ||
and the Azure monitor exporter. | ||
Telemetry is exported to application insights with the AzureMonitorTraceExporter and Zipkin with the | ||
OTLP Span exporter. | ||
""" | ||
import os | ||
from opentelemetry import trace | ||
|
||
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 | ||
|
||
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter | ||
|
||
trace.set_tracer_provider( | ||
TracerProvider( | ||
resource=Resource.create({SERVICE_NAME: "my-zipkin-service"}) | ||
) | ||
) | ||
tracer = trace.get_tracer(__name__) | ||
|
||
exporter = AzureMonitorTraceExporter.from_connection_string( | ||
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] | ||
) | ||
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317") | ||
span_processor = BatchSpanProcessor(otlp_exporter) | ||
trace.get_tracer_provider().add_span_processor(span_processor) | ||
|
||
with tracer.start_as_current_span("test"): | ||
print("Hello world!") | ||
input(...) |
37 changes: 37 additions & 0 deletions
37
sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/sample_jaeger.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
""" | ||
An example to show an application using Opentelemetry tracing api and sdk with multiple exporters. | ||
Telemetry is exported to application insights with the AzureMonitorTraceExporter and Jaeger backend with the JaegerExporter. | ||
""" | ||
import os | ||
from opentelemetry import trace | ||
from opentelemetry.exporter.jaeger.thrift import JaegerExporter | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
|
||
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter | ||
|
||
|
||
exporter = AzureMonitorTraceExporter.from_connection_string( | ||
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] | ||
) | ||
|
||
jaeger_exporter = JaegerExporter( | ||
agent_host_name="localhost", | ||
agent_port=6831, | ||
) | ||
|
||
# Service name needs to be populated for Jaeger to see traces | ||
trace.set_tracer_provider( | ||
TracerProvider( | ||
resource=Resource.create({SERVICE_NAME: "my-jaeger-service"}) | ||
) | ||
) | ||
tracer = trace.get_tracer(__name__) | ||
span_processor = BatchSpanProcessor(exporter) | ||
trace.get_tracer_provider().add_span_processor(span_processor) | ||
|
||
with tracer.start_as_current_span("hello"): | ||
print("Hello, World!") |