Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example, import env var constants #572

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This distribution comes with the following defaults:

## Requirements

This Splunk Distribution of OpenTelemetry requires Python 3.7 or later. Supported
This Splunk Distribution of OpenTelemetry requires Python 3.8 or later. Supported
libraries are listed
[here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation).

Expand Down
19 changes: 19 additions & 0 deletions examples/splunk_opentelemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import time

from opentelemetry import trace
from opentelemetry.sdk.environment_variables import OTEL_SERVICE_NAME
from splunk_otel import init_splunk_otel
from splunk_otel.env import SPLUNK_ACCESS_TOKEN, SPLUNK_REALM

os.environ[OTEL_SERVICE_NAME] = "my-svc"
os.environ[SPLUNK_REALM] = "us1"
os.environ[SPLUNK_ACCESS_TOKEN] = "your-splunk-access-token-here"

# The `init_splunk_otel` command sets up Splunk OTel Python. It is equivalent to running `opentelemetry-instrument`.
init_splunk_otel()

tracer = trace.get_tracer("my-tracer")
for i in range(12):
with tracer.start_as_current_span(f"my-span-{i}"):
time.sleep(0.1)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ exclude_lines = [
]

[tool.ruff.lint]
ignore = ["FA100", "ARG002"]
ignore = ["INP001", "FA100", "ARG002"]
exclude = ["src/splunk_otel/profile_pb2.py"]
39 changes: 26 additions & 13 deletions src/splunk_otel/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,33 @@
import logging
import os

from opentelemetry.environment_variables import OTEL_LOGS_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER
from opentelemetry.sdk.environment_variables import (
OTEL_ATTRIBUTE_COUNT_LIMIT,
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT,
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT,
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS,
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT,
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
OTEL_SPAN_EVENT_COUNT_LIMIT,
OTEL_SPAN_LINK_COUNT_LIMIT,
OTEL_TRACES_SAMPLER,
)

DEFAULTS = {
"OTEL_PYTHON_LOG_CORRELATION": "true", # FIXME: revisit
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_ATTRIBUTE_COUNT_LIMIT": "",
"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT": "",
"OTEL_SPAN_EVENT_COUNT_LIMIT": "",
"OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT": "",
"OTEL_LINK_ATTRIBUTE_COUNT_LIMIT": "",
"OTEL_SPAN_LINK_COUNT_LIMIT": "1000",
"OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT": "12000",
"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": "host,process",
"OTEL_TRACES_SAMPLER": "always_on",
"OTEL_PYTHON_LOG_CORRELATION": "true", # used by opentelemetry-instrumentation-logging (installed by bootstrap)
pmcollins marked this conversation as resolved.
Show resolved Hide resolved
OTEL_TRACES_EXPORTER: "otlp",
OTEL_METRICS_EXPORTER: "otlp",
OTEL_LOGS_EXPORTER: "otlp",
OTEL_ATTRIBUTE_COUNT_LIMIT: "",
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: "",
OTEL_SPAN_EVENT_COUNT_LIMIT: "",
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT: "",
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT: "",
OTEL_SPAN_LINK_COUNT_LIMIT: "1000",
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT: "12000",
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS: "host,process",
OTEL_TRACES_SAMPLER: "always_on",
}

OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED = "OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED"
Expand Down
Loading