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: Use OTel distro class to configure SDK - allow both programatic…
… and auto-configure hooks (#22) ## Which problem is this PR solving? Updates the distro to introduce a the HoneycombDistro class which introduces the hook for auto configuration via BaseDistro. Also exposes the `configure_opentelemetry` function that can be used programatically to configure the SDK. - Closes #10 ## Short description of the changes - Adds new HoneycombDistro class that depends on BaseDistro - Adds `configure_opentelemetry` function that sets up the OTel SDK via environment variables - Adds unit tests for the distro to verify API key, endpoint and service name can be set via parameter or env var NOTE: env vars are used over parameters Co-authored-by: Mike Goldsmth <goldsmith.mike@gmail.com>
- Loading branch information
1 parent
0aa43f0
commit 845508c
Showing
10 changed files
with
253 additions
and
67 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
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 @@ | ||
from honeycomb.opentelemetry.distro import configure_opentelemetry |
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,58 @@ | ||
""" | ||
Add module doc string | ||
""" | ||
import os | ||
from opentelemetry.instrumentation.distro import BaseDistro | ||
from opentelemetry.environment_variables import OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER | ||
from opentelemetry.sdk.environment_variables import ( | ||
OTEL_SERVICE_NAME, | ||
OTEL_EXPORTER_OTLP_PROTOCOL, | ||
OTEL_EXPORTER_OTLP_HEADERS, | ||
OTEL_EXPORTER_OTLP_ENDPOINT | ||
) | ||
|
||
HONEYCOMB_API_KEY = "HONEYCOMB_API_KEY" | ||
HONEYCOMB_API_ENDPOINT = "HONEYCOMB_API_ENDPOINT" | ||
|
||
DEFAULT_API_ENDPOINT = "api.honeycomb.io:443" | ||
DEFAULT_SERVICE_NAME = "unknown_service:python" | ||
|
||
|
||
def configure_opentelemetry( | ||
apikey: str = None, | ||
service_name: str = None, | ||
endpoint: str = None | ||
): | ||
os.environ.setdefault(OTEL_EXPORTER_OTLP_PROTOCOL, "grpc") | ||
os.environ.setdefault(OTEL_TRACES_EXPORTER, "otlp") | ||
# disable metrics for now | ||
os.environ.setdefault(OTEL_METRICS_EXPORTER, "none") | ||
|
||
service_name = os.environ.get(OTEL_SERVICE_NAME, service_name) | ||
if not service_name: | ||
# TODO - warn no service name set, defaulting to unknown_service:python | ||
service_name = DEFAULT_SERVICE_NAME | ||
os.environ.setdefault(OTEL_SERVICE_NAME, service_name) | ||
|
||
endpoint = os.environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, endpoint) | ||
if not endpoint: | ||
endpoint = DEFAULT_API_ENDPOINT | ||
os.environ.setdefault(OTEL_EXPORTER_OTLP_ENDPOINT, endpoint) | ||
|
||
apikey = os.environ.get(HONEYCOMB_API_KEY, apikey) | ||
if apikey: | ||
os.environ.setdefault(OTEL_EXPORTER_OTLP_HEADERS, | ||
f"x-honeycomb-team={apikey}") | ||
else: | ||
# TODO - warn no API key set | ||
pass | ||
|
||
|
||
class HoneycombDistro(BaseDistro): | ||
""" | ||
The OpenTelemetry provided Distro configures a default set of | ||
configuration out of the box. | ||
""" | ||
|
||
def _configure(self, **kwargs): | ||
configure_opentelemetry() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.