Configuring the SDK with Environment Variables and Files: OTCA practice questions
Every SDK must offer programmatic configuration, and most also read a common set of environment variables. Support for these variables varies by language, so the compliance matrix is the place to check a specific SDK. Values are parsed in a fixed way. An empty value counts as unset.
By Ibrahim Yesilay · Published · Updated
Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.
What Configuring the SDK with Environment Variables and Files covers in OTCA
Every SDK must offer programmatic configuration, and most also read a common set of environment variables. Support for these variables varies by language, so the compliance matrix is the place to check a specific SDK. Values are parsed in a fixed way. An empty value counts as unset. Booleans become true only for the case-insensitive string true, so setting OTEL_SDK_DISABLED=1 leaves the SDK enabled. Enum values are case-insensitive, and unknown values produce a warning and are ignored.
The resource is usually set first. OTEL_SERVICE_NAME sets service.name and wins over a service.name entry in OTEL_RESOURCE_ATTRIBUTES. That second variable takes comma-separated key=value pairs whose values are strings; commas and equals signs inside keys or values must be percent-encoded. Resource data provided in code has higher priority than the environment variable. If no service name is configured, the semantic conventions require unknown_service: followed by the executable name.
Sampling is controlled by OTEL_TRACES_SAMPLER, which defaults to parentbased_always_on. Other values include always_on, always_off, traceidratio and parentbased_traceidratio. OTEL_TRACES_SAMPLER_ARG supplies an argument such as a ratio between 0 and 1, but it is used only when OTEL_TRACES_SAMPLER is also set. Exporters are chosen per signal with OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER and OTEL_LOGS_EXPORTER, which all default to otlp. The value none turns off the automatically configured exporter for that signal, while console prints to standard output. For periodic metric export, OTEL_METRIC_EXPORT_INTERVAL defaults to 60000 milliseconds and OTEL_METRIC_EXPORT_TIMEOUT to 30000.
The OTLP exporter has its own family of variables. OTEL_EXPORTER_OTLP_PROTOCOL accepts grpc, http/protobuf and http/json, and the spec says the default should be http/protobuf unless an SDK keeps grpc for backward compatibility. Default endpoints are localhost on port 4317 for gRPC and 4318 for HTTP. With OTLP/HTTP, OTEL_EXPORTER_OTLP_ENDPOINT is a base URL to which v1/traces, v1/metrics or v1/logs is appended, but the signal-specific endpoint variables are used exactly as written. Headers use the key1=value1,key2=value2 format, and the default export timeout is ten seconds.
Limits protect memory. OTEL_ATTRIBUTE_COUNT_LIMIT defaults to 128 attributes, and attribute value length is unlimited unless configured. Model-specific variables such as OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT are checked before the general one.
Declarative configuration describes the whole SDK in a YAML file named by OTEL_CONFIG_FILE, which replaces the deprecated OTEL_EXPERIMENTAL_CONFIG_FILE. The schema is marked stable, but SDK support is still experimental. Once the file is in use, other environment variables are ignored unless the file references them with substitution syntax such as ${OTEL_EXPORTER_OTLP_ENDPOINT}.
Key points
- OTEL_SERVICE_NAME takes precedence over service.name in OTEL_RESOURCE_ATTRIBUTES.
- The default sampler is parentbased_always_on, and OTEL_TRACES_SAMPLER_ARG is used only when a sampler is set.
- Trace, metric and log exporters default to otlp, and the value none disables automatic exporter setup for a signal.
- OTLP/HTTP appends v1/<signal> to the base endpoint but uses signal-specific endpoints as written.
- When OTEL_CONFIG_FILE is set, environment variables not referenced in the file are ignored.
Three sample questions
22 OTCA questions on Configuring the SDK with Environment Variables and Files, 22 with explanations. How practice works
Question 1
OTEL_RESOURCE_ATTRIBUTES=service.name=billing,deployment.environment.name=prod
OTEL_SERVICE_NAME=billing-api- A.billing, because OTEL_RESOURCE_ATTRIBUTES is applied after OTEL_SERVICE_NAME
- B.Both values, joined as billing,billing-api in one attribute
- C.unknown_service, because conflicting values cancel each other
- D.billing-api, because OTEL_SERVICE_NAME takes precedence
Correct answer: D
Sources: OpenTelemetry spec: Environment Variable Specification, OpenTelemetry docs: General SDK Configuration
Question 2
- A.api-key=abc123,tenant=team-a
- B.X-Api-Key: abc123; X-Tenant: team-a
- C.{"api-key": "abc123", "x-tenant": "team-a"}
- D.api-key=abc123;tenant=team-a;region=eu
Correct answer: A
Sources: OpenTelemetry spec: OTLP Exporter configuration, OpenTelemetry docs: OTLP Exporter Configuration
Question 3
- A.prod, because environment variables always override values set in code
- B.staging, because user-provided resource data has higher priority
- C.Neither; the SDK reports a merge error and drops the attribute
- D.Both, kept as two attributes with the same key
Correct answer: B
Sources: OpenTelemetry spec: Resource SDK, OpenTelemetry spec: Common concepts (attribute limits)
Practice this topic
Focus mode keeps every question on Configuring the SDK with Environment Variables and Files until you leave it. 10 free guest answers, then a free account; no credit card.
Or open OTCA practice across all topics.
Sources
The explanation above was checked against these official documents.
- OpenTelemetry spec: Environment Variable Specification (checked 2026-10-28)
- OpenTelemetry spec: OTLP Exporter configuration (checked 2026-10-28)
- OpenTelemetry docs: General SDK Configuration (checked 2026-10-28)
- OpenTelemetry docs: OTLP Exporter Configuration (checked 2026-10-28)
- OpenTelemetry docs: Declarative configuration (checked 2026-10-28)
- OpenTelemetry spec: Resource SDK (checked 2026-10-28)
- OpenTelemetry semantic conventions: Service resource (checked 2026-10-28)
Frequently asked questions
Why does OTEL_SDK_DISABLED=1 not disable the SDK?
Boolean variables are true only for the case-insensitive string true. Any other value, including 1, is read as false, and the SDK should log a warning.
What is the default OTLP protocol?
The specification says it should be http/protobuf, but SDKs may keep grpc for backward compatibility, so the docs describe the default as SDK-dependent.