generated from honeycombio/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configure traces and metrics pipelines (#27)
## Which problem is this PR solving? As we develop more functionality into the Honeycomb distro, setting environment variables doesn't offer enough flexability for our needs. This PR updates the distro to instead configure both the tracer and meter providers directly by configuring their exporters. This will enable additional resources (eg span processors or samplers) to be added later. - Closes #14 - Closes #11 ## Short description of the changes - [x] Adds openetelemetry-otlp-exporter as dependency - [x] Add create_tracer_provider func to tracing.py - [x] Add create_meter_provider func to metrics.py - [x] Wire tracing and meter provider pipelines using options & resource in distro/configure_opentelemetry - [x] Update HoneycombOptions with member functions to get trace & meter exporter credentials & headers - [x] Add simple test to verify new tracer / meter provider creation funcs return expected types - [x] Remove env var based tests from test_distro.py - [x] Update distro/configure_opentelemetry to take HoneycombOptions arg instead of discrete optional fields - [x] Re-add custom instrumentation to example app to show how to create additional spans Co-authored-by: Robb Kidd <robbkidd@honeycomb.io>
- Loading branch information
1 parent
ef751a0
commit 460da85
Showing
14 changed files
with
695 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ bin | |
.vscode | ||
.coverage | ||
htmlcov | ||
.env | ||
test-results/ |
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from flask import Flask | ||
from opentelemetry import trace | ||
|
||
app = Flask(__name__) | ||
|
||
tracer = trace.get_tracer(__name__) | ||
|
||
@app.route("/") | ||
def hello_world(): | ||
with tracer.start_as_current_span("foo"): | ||
with tracer.start_as_current_span("bar"): | ||
print("baz") | ||
return "Hello World" |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from honeycomb.opentelemetry.distro import configure_opentelemetry | ||
from honeycomb.opentelemetry.options import HoneycombOptions |
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
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,23 @@ | ||
from honeycomb.opentelemetry.options import HoneycombOptions | ||
from opentelemetry.sdk.resources import Resource | ||
from opentelemetry.sdk.metrics import MeterProvider | ||
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader | ||
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import ( | ||
OTLPMetricExporter | ||
) | ||
|
||
|
||
def create_meter_provider(options: HoneycombOptions, resource: Resource): | ||
exporter = OTLPMetricExporter( | ||
endpoint=options.endpoint, | ||
credentials=options.get_metrics_endpoint_credentials(), | ||
headers=options.get_metrics_headers() | ||
) | ||
reader = PeriodicExportingMetricReader( | ||
exporter, | ||
export_timeout_millis=10000 # TODO set via OTEL env var | ||
) | ||
return MeterProvider( | ||
metric_readers=[reader], | ||
resource=resource | ||
) |
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
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 @@ | ||
from honeycomb.opentelemetry.options import HoneycombOptions | ||
from opentelemetry.sdk.resources import Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import ( | ||
OTLPSpanExporter | ||
) | ||
|
||
|
||
def create_tracer_provider(options: HoneycombOptions, resource: Resource): | ||
trace_provider = TracerProvider(resource=resource) | ||
trace_provider.add_span_processor( | ||
BatchSpanProcessor( | ||
OTLPSpanExporter( | ||
endpoint=options.endpoint, | ||
credentials=options.get_trace_endpoint_credentials(), | ||
headers=options.get_trace_headers() | ||
) | ||
) | ||
) | ||
return trace_provider |
Oops, something went wrong.