Skip to content

Commit

Permalink
Add oteltest for missing svcname
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcollins committed Dec 5, 2024
1 parent e4f3ce0 commit 34cd124
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/ott_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def requirements(self):
return (project_path(),)

def environment_variables(self):
return {}
return {
"OTEL_PYTHON_DISABLED_INSTRUMENTATIONS": "system_metrics",
"OTEL_SERVICE_NAME": "spec-svc",
}

def wrapper_command(self):
return "opentelemetry-instrument"
Expand All @@ -20,9 +23,6 @@ def on_start(self):
def on_stop(self, telemetry, stdout: str, stderr: str, returncode: int) -> None:
from oteltest.telemetry import extract_leaves, get_attribute

def get_attribute_str(attrs, key):
return get_attribute(attrs, key).value.string_value

attributes = extract_leaves(
telemetry,
"trace_requests",
Expand All @@ -36,10 +36,12 @@ def get_attribute_str(attrs, key):
assert get_attribute(attributes, "telemetry.sdk.version")
assert get_attribute(attributes, "telemetry.sdk.language")

assert get_attribute_str(attributes, "telemetry.distro.version")
assert get_attribute_str(attributes, "telemetry.distro.name") == "splunk-opentelemetry"
assert get_attribute(attributes, "telemetry.distro.version").value.string_value
assert get_attribute(attributes, "telemetry.distro.name").value.string_value == "splunk-opentelemetry"

assert get_attribute(attributes, "process.pid")

assert get_attribute(attributes, "service.name").value.string_value == "spec-svc"

def is_http(self):
return False
38 changes: 38 additions & 0 deletions tests/ott_svcname_unset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from ott_lib import project_path, trace_loop

if __name__ == "__main__":
trace_loop(1)


class SpecOtelTest:
def requirements(self):
return (project_path(),)

def environment_variables(self):
return {
"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 extract_leaves, get_attribute

assert "service.name attribute is not set" in stderr

attributes = extract_leaves(
telemetry,
"trace_requests",
"pbreq",
"resource_spans",
"resource",
"attributes",
)
assert get_attribute(attributes, "service.name").value.string_value == "unnamed-python-service"

def is_http(self):
return False

0 comments on commit 34cd124

Please sign in to comment.