From d938dae38f706517cf588e12ffa2698f7b55b7d2 Mon Sep 17 00:00:00 2001 From: Pablo Collins Date: Tue, 10 Dec 2024 10:24:18 -0500 Subject: [PATCH] Add http exporter oteltest. Move sf token constant. --- src/splunk_otel/distro.py | 4 ++-- src/splunk_otel/env.py | 2 -- tests/ott_http.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/ott_http.py diff --git a/src/splunk_otel/distro.py b/src/splunk_otel/distro.py index 20117ff..6f9ec42 100644 --- a/src/splunk_otel/distro.py +++ b/src/splunk_otel/distro.py @@ -31,7 +31,6 @@ SPLUNK_PROFILER_ENABLED, SPLUNK_PROFILER_LOGS_ENDPOINT, SPLUNK_TRACE_RESPONSE_HEADER_ENABLED, - X_SF_TOKEN, Env, ) from splunk_otel.propagator import ServerTimingResponsePropagator @@ -42,6 +41,7 @@ Set your service name using the OTEL_SERVICE_NAME environment variable. e.g. `OTEL_SERVICE_NAME=""`""" _DEFAULT_SERVICE_NAME = "unnamed-python-service" +_X_SF_TOKEN = "x-sf-token" # noqa S105 _pylogger = logging.getLogger(__name__) @@ -87,7 +87,7 @@ def set_resource_attributes(self): def configure_headers(self): tok = self.env.getval(SPLUNK_ACCESS_TOKEN).strip() if tok: - self.env.list_append(OTEL_EXPORTER_OTLP_HEADERS, f"{X_SF_TOKEN}={tok}") + self.env.list_append(OTEL_EXPORTER_OTLP_HEADERS, f"{_X_SF_TOKEN}={tok}") def set_server_timing_propagator(self): if self.env.is_true(SPLUNK_TRACE_RESPONSE_HEADER_ENABLED, "true"): diff --git a/src/splunk_otel/env.py b/src/splunk_otel/env.py index 59658d5..ee2541f 100644 --- a/src/splunk_otel/env.py +++ b/src/splunk_otel/env.py @@ -40,8 +40,6 @@ SPLUNK_PROFILER_CALL_STACK_INTERVAL = "SPLUNK_PROFILER_CALL_STACK_INTERVAL" SPLUNK_PROFILER_LOGS_ENDPOINT = "SPLUNK_PROFILER_LOGS_ENDPOINT" -X_SF_TOKEN = "x-sf-token" # noqa S105 - _pylogger = logging.getLogger(__name__) diff --git a/tests/ott_http.py b/tests/ott_http.py new file mode 100644 index 0000000..91d75c4 --- /dev/null +++ b/tests/ott_http.py @@ -0,0 +1,30 @@ +from ott_lib import project_path, trace_loop + +if __name__ == "__main__": + trace_loop(1) + + +class MyOtelTest: + def requirements(self): + return (project_path(),) + + def environment_variables(self): + return { + "OTEL_SERVICE_NAME": "my-otel-test", + "OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf", + "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS": "system_metrics", + } + + def wrapper_command(self): + return "opentelemetry-instrument" + + def on_start(self): + return None + + def on_stop(self, telemetry, stdout: str, stderr: str, returncode: int) -> None: + from oteltest.telemetry import count_spans + + assert count_spans(telemetry) + + def is_http(self): + return True