Skip to content

Commit

Permalink
Add http exporter oteltest.
Browse files Browse the repository at this point in the history
Move sf token constant.
  • Loading branch information
pmcollins committed Dec 10, 2024
1 parent 5dfb3b5 commit d938dae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/splunk_otel/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +41,7 @@
Set your service name using the OTEL_SERVICE_NAME environment variable.
e.g. `OTEL_SERVICE_NAME="<YOUR_SERVICE_NAME_HERE>"`"""
_DEFAULT_SERVICE_NAME = "unnamed-python-service"
_X_SF_TOKEN = "x-sf-token" # noqa S105

_pylogger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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"):
Expand Down
2 changes: 0 additions & 2 deletions src/splunk_otel/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
30 changes: 30 additions & 0 deletions tests/ott_http.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d938dae

Please sign in to comment.