dash0-opentelemetry 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/CLAUDE.md +117 -0
- data/README.md +23 -3
- data/RELEASING.md +10 -5
- data/lib/dash0/opentelemetry/boot.rb +52 -9
- data/lib/dash0/opentelemetry/declarative_config/metric_views.rb +92 -0
- data/lib/dash0/opentelemetry/declarative_config/metrics.rb +179 -0
- data/lib/dash0/opentelemetry/declarative_config/resource_detectors.rb +80 -0
- data/lib/dash0/opentelemetry/declarative_config.rb +52 -0
- data/lib/dash0/opentelemetry/resource/service_name_fallback.rb +18 -2
- data/lib/dash0/opentelemetry/sdk_configuration.rb +41 -2
- data/lib/dash0/opentelemetry/version.rb +1 -1
- data/lib/dash0/opentelemetry.rb +1 -0
- metadata +51 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03a7be79ff0a2fdbb1378fda646246de991735584d586cd4e20579041ada6d76
|
|
4
|
+
data.tar.gz: 266d25f26f2c6df97a6edc76dbfccad8ffc8fdd44478bc3513910e90161c54bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99b50e252eff0d11d02c7d482afc084839a0907cefa246149f108c6519843a7bbbb15db773017b119519cbb700ba0f9b4df8ba45d8c650e742b962be17ff6414
|
|
7
|
+
data.tar.gz: abed88cb5fe610680d332313ec77ae1628479bf27f8b68bd997955e19cd1cd3507266a7e0fbdb41cfb75cf8d96c32add89f3790167ec2f57ede09e4605c85bed
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.2.0] - 2026-11-23
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Configure the OpenTelemetry SDK from a declarative configuration file by setting `OTEL_CONFIG_FILE`, as an alternative to `DASH0_OTEL_COLLECTOR_BASE_URL`. The file supports traces, metrics, logs, and `${VARIABLE}` substitution, and can name the `dash0_distribution`, `dash0_kubernetes`, and `dash0_service_name` resource detectors. (#32)
|
|
16
|
+
- When `OTEL_CONFIG_FILE` is unset, read the declarative configuration file at `/etc/opentelemetry/ruby/otel-config.yaml` if it exists, before falling back to environment variables. With a configuration file, `DASH0_OTEL_COLLECTOR_BASE_URL` defaults `OTEL_EXPORTER_OTLP_ENDPOINT` instead of being ignored. (#40)
|
|
17
|
+
- Instrument the `openai` gem automatically, by updating `opentelemetry-instrumentation-all` to 0.99.0. (#31)
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **Breaking:** the default propagators change from `tracecontext,baggage` to `tracecontext,baggage,xray`, bundling `opentelemetry-propagator-xray` so traces stay connected through AWS load balancers. The X-Ray context wins over `traceparent` when both are present. Set `OTEL_PROPAGATORS=tracecontext,baggage` to restore the previous behavior. (#39)
|
|
22
|
+
|
|
11
23
|
## [0.1.0] - 2026-07-31
|
|
12
24
|
|
|
13
25
|
### Added
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
Maintenance instructions for the Dash0 OpenTelemetry Ruby Distribution.
|
|
4
|
+
|
|
5
|
+
## Project overview
|
|
6
|
+
|
|
7
|
+
This is a Ruby gem (`dash0-opentelemetry`) that auto-instruments Ruby applications
|
|
8
|
+
via `RUBYOPT="-r dash0-opentelemetry"`.
|
|
9
|
+
All code lives under `lib/`.
|
|
10
|
+
The gem is primarily injected by the Dash0 Kubernetes operator; the `packaging/`
|
|
11
|
+
directory holds the standalone gem bundle the operator mounts into pods.
|
|
12
|
+
|
|
13
|
+
Key modules:
|
|
14
|
+
|
|
15
|
+
- `lib/dash0-opentelemetry.rb` — entry point; Ruby-version gate lives here so it
|
|
16
|
+
can run on older Rubies before requiring any other file.
|
|
17
|
+
- `lib/dash0/opentelemetry/boot.rb` — orchestrates startup gates and calls into
|
|
18
|
+
SDK configuration, instrumentation installer, and lifecycle setup.
|
|
19
|
+
- `lib/dash0/opentelemetry/environment.rb` — helpers for reading env vars.
|
|
20
|
+
- `lib/dash0/opentelemetry/sdk_configuration.rb` — configures OpenTelemetry SDK,
|
|
21
|
+
sets OTLP exporter defaults, builds the resource.
|
|
22
|
+
- `lib/dash0/opentelemetry/instrumentation_installer.rb` — lazy instrumentation
|
|
23
|
+
via `TracePoint(:end)`.
|
|
24
|
+
- `lib/dash0/opentelemetry/lifecycle.rb` — bootstrap span, SIGTERM/SIGINT handlers,
|
|
25
|
+
`at_exit` flush.
|
|
26
|
+
- `lib/dash0/opentelemetry/resource/` — three custom resource detectors:
|
|
27
|
+
`distribution.rb`, `kubernetes_pod.rb`, `service_name_fallback.rb`.
|
|
28
|
+
- `lib/dash0/opentelemetry/declarative_config.rb` and `declarative_config/` —
|
|
29
|
+
`OTEL_CONFIG_FILE` support on top of `opentelemetry-config`: copies of
|
|
30
|
+
unreleased upstream changes (the meter provider and metric views) and the
|
|
31
|
+
patch that lets a file name the Dash0 resource detectors.
|
|
32
|
+
|
|
33
|
+
## Coding conventions
|
|
34
|
+
|
|
35
|
+
- SPDX header on every file: `# SPDX-FileCopyrightText: Copyright 2026 Dash0 Inc.`
|
|
36
|
+
and `# SPDX-License-Identifier: Apache-2.0`.
|
|
37
|
+
- Ruby >= 3.3 may be assumed in all files under `lib/dash0/` (but not in
|
|
38
|
+
`lib/dash0-opentelemetry.rb`, which must stay parse-safe on older Rubies).
|
|
39
|
+
- Fail open: catch `StandardError, ScriptError` at startup boundaries and log
|
|
40
|
+
rather than raise.
|
|
41
|
+
- Use `Environment.set_default` (never `ENV[name] =`) when setting OTLP defaults,
|
|
42
|
+
so an explicit operator/user value is never overwritten.
|
|
43
|
+
- Instrumentation names in user-facing text use snake_case (e.g. `net_http`,
|
|
44
|
+
`active_record`).
|
|
45
|
+
|
|
46
|
+
## Source of truth for each doc
|
|
47
|
+
|
|
48
|
+
When the code changes, update the corresponding doc.
|
|
49
|
+
|
|
50
|
+
| Doc | Authoritative source file(s) |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `docs/overview.md` | `README.md`, `lib/dash0-opentelemetry.rb`, `dash0-opentelemetry.gemspec` |
|
|
53
|
+
| `docs/getting-started.md` | `README.md` |
|
|
54
|
+
| `docs/configuration.md` | `lib/dash0/opentelemetry/environment.rb`, `lib/dash0/opentelemetry/sdk_configuration.rb`, `lib/dash0/opentelemetry/lifecycle.rb`, `lib/dash0/opentelemetry/resource/service_name_fallback.rb`, `lib/dash0/opentelemetry/declarative_config.rb`, `lib/dash0/opentelemetry/declarative_config/`, `test/fixtures/otel-config.yaml` |
|
|
55
|
+
| `docs/auto-instrumentation.md` | `packaging/Gemfile.lock`, `lib/dash0/opentelemetry/instrumentation_installer.rb` |
|
|
56
|
+
| `docs/resource-detection.md` | `lib/dash0/opentelemetry/resource/distribution.rb`, `lib/dash0/opentelemetry/resource/kubernetes_pod.rb`, `lib/dash0/opentelemetry/resource/service_name_fallback.rb`, `lib/dash0/opentelemetry/sdk_configuration.rb`, `lib/dash0/opentelemetry/declarative_config/resource_detectors.rb` |
|
|
57
|
+
| `docs/kubernetes-injection.md` | `lib/dash0-opentelemetry.rb`, `lib/dash0/opentelemetry/boot.rb`, `lib/dash0/opentelemetry/sdk_configuration.rb` |
|
|
58
|
+
|
|
59
|
+
## Rules for updating docs
|
|
60
|
+
|
|
61
|
+
**When a `DASH0_*` or `OTEL_*` env var is added, removed, or renamed:**
|
|
62
|
+
Update `docs/configuration.md`.
|
|
63
|
+
Also update `docs/getting-started.md` if the startup sequence changes.
|
|
64
|
+
Also update `docs/kubernetes-injection.md` if injection-specific behavior changes.
|
|
65
|
+
|
|
66
|
+
**When a resource detector is added, changed, or removed:**
|
|
67
|
+
Update `docs/resource-detection.md`.
|
|
68
|
+
Also update `docs/overview.md` if the resource attribute summary there changes.
|
|
69
|
+
|
|
70
|
+
**When the instrumentation list changes** (i.e. `opentelemetry-instrumentation-all`
|
|
71
|
+
is updated in `dash0-opentelemetry.gemspec` and `packaging/Gemfile.lock` is
|
|
72
|
+
regenerated):
|
|
73
|
+
Derive `docs/auto-instrumentation.md`'s instrumentation tables from
|
|
74
|
+
`packaging/Gemfile.lock`.
|
|
75
|
+
The direct dependencies of `opentelemetry-instrumentation-all` and
|
|
76
|
+
`opentelemetry-instrumentation-rails` are the canonical source; extract them with:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
awk '/^ opentelemetry-instrumentation-(all|rails) \(/{f=1;next} /^ [^ ]/{f=0} f' packaging/Gemfile.lock \
|
|
80
|
+
| sed 's/.*opentelemetry-instrumentation-//; s/ (.*//' \
|
|
81
|
+
| sort -u
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`aws_lambda` is omitted from the tables because it requires wrapping the handler manually.
|
|
85
|
+
|
|
86
|
+
Never update the instrumentation tables by hand.
|
|
87
|
+
|
|
88
|
+
**When the example configuration file in `docs/configuration.md` changes:**
|
|
89
|
+
Update `test/fixtures/otel-config.yaml` to match; the integration tests boot from
|
|
90
|
+
it and a unit test checks the two are identical.
|
|
91
|
+
|
|
92
|
+
**When injection behavior changes** (startup gates, RUBYOPT mechanism,
|
|
93
|
+
OTEL_RUBY_ADDITIONAL_GEM_PATH, DISALLOWED_LIB_PATH):
|
|
94
|
+
Update `docs/kubernetes-injection.md` and `docs/configuration.md`.
|
|
95
|
+
|
|
96
|
+
## Keeping transformations.yaml in sync
|
|
97
|
+
|
|
98
|
+
`.github/workflows/sync-docs/transformations.yaml` must list every file under
|
|
99
|
+
`docs/*.md` in the `files:` block.
|
|
100
|
+
The `coverage:` block enforces this in CI, so adding a doc file without updating
|
|
101
|
+
`transformations.yaml` will break the sync workflow.
|
|
102
|
+
When adding a new doc:
|
|
103
|
+
1. Add a `- source: / target: / title:` entry to the `files:` block.
|
|
104
|
+
2. Update the source-of-truth table in this file.
|
|
105
|
+
3. Update `docs/overview.md` if the new page warrants a mention.
|
|
106
|
+
|
|
107
|
+
## Style rules for docs
|
|
108
|
+
|
|
109
|
+
- One sentence per line in the Markdown source (not one sentence per paragraph).
|
|
110
|
+
- Sentence-case headings (capitalize only the first word and proper nouns).
|
|
111
|
+
- Active voice.
|
|
112
|
+
- Inline code (backticks) for all variable names, gem names, file paths, env vars,
|
|
113
|
+
and instrumentation names.
|
|
114
|
+
- No em-dashes; use a comma, semicolon, or rewrite the sentence.
|
|
115
|
+
- Three-column tables for instrumentation lists: Library | Gem | Instrumentation name.
|
|
116
|
+
- Two-column tables for env var lists: Variable | Description.
|
|
117
|
+
- No trailing whitespace, no blank lines inside table rows.
|
data/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/dash0-opentelemetry)
|
|
2
|
+
|
|
1
3
|
# Dash0 OpenTelemetry Distribution for Ruby
|
|
2
4
|
|
|
3
5
|
An opinionated, zero-code [OpenTelemetry](https://opentelemetry.io) distribution
|
|
@@ -53,14 +55,15 @@ On startup the distribution:
|
|
|
53
55
|
|
|
54
56
|
## Configuration
|
|
55
57
|
|
|
56
|
-
Behavior is driven
|
|
57
|
-
distribution-specific switches and standard `OTEL_*` for the rest.
|
|
58
|
+
Behavior is driven by environment variables: `DASH0_*` for
|
|
59
|
+
distribution-specific switches and standard `OTEL_*` for the rest. The SDK can
|
|
60
|
+
also be configured with a declarative configuration file (see below).
|
|
58
61
|
|
|
59
62
|
### `DASH0_*` variables
|
|
60
63
|
|
|
61
64
|
| Variable | Description |
|
|
62
65
|
| --- | --- |
|
|
63
|
-
| `DASH0_OTEL_COLLECTOR_BASE_URL` | **Required
|
|
66
|
+
| `DASH0_OTEL_COLLECTOR_BASE_URL` | **Required** unless a configuration file is used (see [Declarative configuration](#declarative-configuration)). Base URL of the OpenTelemetry collector to export to; each signal is sent to `<base>/v1/{traces,metrics,logs}`. If neither is set, the distribution stands down and exports nothing. (The Dash0 operator sets this for you.) |
|
|
64
67
|
| `DASH0_DISABLE` | Set to `true` to disable the distribution entirely. |
|
|
65
68
|
| `DASH0_AUTOMATIC_SERVICE_NAME` | Set to `false` to opt out of the automatic `service.name` fallback (see below). |
|
|
66
69
|
| `DASH0_BOOTSTRAP_SPAN` | If set to a non-empty string, a single internal span with that name is emitted immediately at startup. Useful for confirming the distribution is active. |
|
|
@@ -97,17 +100,34 @@ stock OpenTelemetry SDK, exporters, and processors. Commonly useful ones:
|
|
|
97
100
|
|
|
98
101
|
| Variable | Description |
|
|
99
102
|
| --- | --- |
|
|
103
|
+
| `OTEL_CONFIG_FILE` | Path to a declarative configuration file. When set, the file configures the SDK instead of environment variables (see below). When unset, `/etc/opentelemetry/ruby/otel-config.yaml` is used if it exists. |
|
|
100
104
|
| `OTEL_SERVICE_NAME` | Sets `service.name` explicitly (and disables the automatic fallback). |
|
|
101
105
|
| `OTEL_RESOURCE_ATTRIBUTES` | Additional resource attributes as `key=value` pairs. A `service.name` here also disables the automatic fallback. |
|
|
102
106
|
| `OTEL_RUBY_ENABLED_INSTRUMENTATIONS` | Comma-separated allowlist of instrumentations to enable (by snake_case name, e.g. `net_http,rack`). When unset, all supported instrumentations are enabled. |
|
|
103
107
|
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Overrides the OTLP endpoint. Defaulted from `DASH0_OTEL_COLLECTOR_BASE_URL`; set explicitly only to override. |
|
|
104
108
|
| `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP protocol; defaults to `http/protobuf` (the only protocol supported by the Ruby SDK's default path). |
|
|
105
109
|
| `OTEL_EXPORTER_OTLP_HEADERS` | Extra headers for the OTLP exporter (e.g. an authorization token when exporting directly to Dash0 rather than through the operator's collector). |
|
|
110
|
+
| `OTEL_PROPAGATORS` | Context propagators; defaults to `tracecontext,baggage,xray`, so W3C `traceparent` and `baggage` and AWS X-Ray `X-Amzn-Trace-Id` headers are read and written (X-Ray wins on extract when both carry a parent). Set explicitly to override, e.g. `tracecontext,baggage` to drop X-Ray. |
|
|
106
111
|
| `OTEL_METRIC_EXPORT_INTERVAL` / `OTEL_METRIC_EXPORT_TIMEOUT` | Periodic metric reader interval / timeout, in milliseconds. |
|
|
107
112
|
|
|
108
113
|
Standard batch-processor variables (`OTEL_BSP_*`, `OTEL_BLRP_*`) and
|
|
109
114
|
`OTEL_SDK_DISABLED` are honored by the underlying SDK as well.
|
|
110
115
|
|
|
116
|
+
### Declarative configuration
|
|
117
|
+
|
|
118
|
+
Set `OTEL_CONFIG_FILE` to the path of an OpenTelemetry
|
|
119
|
+
[declarative configuration file](https://opentelemetry.io/docs/languages/sdk-configuration/declarative-configuration/)
|
|
120
|
+
to configure the SDK from the file instead of environment variables. When
|
|
121
|
+
`OTEL_CONFIG_FILE` is unset, the distribution uses
|
|
122
|
+
`/etc/opentelemetry/ruby/otel-config.yaml` if that file exists.
|
|
123
|
+
`DASH0_OTEL_COLLECTOR_BASE_URL` still sets the default for
|
|
124
|
+
`OTEL_EXPORTER_OTLP_ENDPOINT`, which the file can reference, and other `OTEL_*`
|
|
125
|
+
variables only apply when the file references them with `${VARIABLE}`
|
|
126
|
+
substitution. The file can name the `dash0_distribution`, `dash0_kubernetes`,
|
|
127
|
+
and `dash0_service_name` resource detectors. See
|
|
128
|
+
[docs/configuration.md](docs/configuration.md#declarative-configuration) for an
|
|
129
|
+
example and details.
|
|
130
|
+
|
|
111
131
|
### `DISALLOWED_LIB_PATH` (advanced)
|
|
112
132
|
|
|
113
133
|
A comma-separated list of bundled non-`opentelemetry-*` gems the distribution
|
data/RELEASING.md
CHANGED
|
@@ -43,11 +43,16 @@ tag on a merged commit and (b) an explicit human approval on the environment.
|
|
|
43
43
|
git push origin main --tags
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
6. The `Release` workflow runs the full verification (`bundle exec rake`)
|
|
47
|
-
|
|
46
|
+
6. The `Release` workflow runs the full verification (`bundle exec rake`), builds
|
|
47
|
+
and publishes the gem to RubyGems via trusted publishing, and publishes a
|
|
48
|
+
GitHub release for the tag with that version's `CHANGELOG.md` section as
|
|
49
|
+
release notes and the built `.gem` attached as a release asset.
|
|
48
50
|
|
|
49
51
|
## After a release
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
The Dash0 operator's weekly `Check for Dash0 Ruby Distribution Updates`
|
|
54
|
+
workflow discovers the new version via `gh release list` against this
|
|
55
|
+
repository and opens a PR bumping the pinned version, so no manual step is
|
|
56
|
+
required there. That PR still updates the operator's Ruby build stage (install
|
|
57
|
+
`dash0-opentelemetry` and point the injector entry symlink at it) — tracked in
|
|
58
|
+
the operator repository, not here.
|
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
module Dash0
|
|
7
7
|
module OpenTelemetry
|
|
8
|
-
# Orchestrates startup: gating (disable switch,
|
|
9
|
-
# double-instrumentation guard), SDK configuration, and
|
|
10
|
-
# install.
|
|
8
|
+
# Orchestrates startup: gating (disable switch, collector URL or config
|
|
9
|
+
# file, double-instrumentation guard), SDK configuration, and
|
|
10
|
+
# instrumentation install.
|
|
11
11
|
#
|
|
12
12
|
# The Ruby-version stand-down lives in the requirable entry point
|
|
13
13
|
# (`lib/dash0-opentelemetry.rb`) so it can run before any modern-syntax file
|
|
14
14
|
# is required.
|
|
15
15
|
module Boot
|
|
16
16
|
COLLECTOR_BASE_URL_ENV = 'DASH0_OTEL_COLLECTOR_BASE_URL'
|
|
17
|
+
CONFIG_FILE_ENV = 'OTEL_CONFIG_FILE'
|
|
18
|
+
DEFAULT_CONFIG_FILE = '/etc/opentelemetry/ruby/otel-config.yaml'
|
|
17
19
|
DISABLE_ENV = 'DASH0_DISABLE'
|
|
18
20
|
|
|
19
21
|
class << self
|
|
@@ -23,8 +25,11 @@ module Dash0
|
|
|
23
25
|
return if @booted
|
|
24
26
|
return if disabled?
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
config_file = config_file_path
|
|
29
|
+
unless config_file
|
|
30
|
+
base_url = collector_base_url
|
|
31
|
+
return unless base_url
|
|
32
|
+
end
|
|
28
33
|
|
|
29
34
|
if already_instrumented?
|
|
30
35
|
Dash0::OpenTelemetry.log_error(
|
|
@@ -34,7 +39,7 @@ module Dash0
|
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
@booted = true
|
|
37
|
-
configure(base_url)
|
|
42
|
+
config_file ? configure_from_file(config_file) : configure(base_url)
|
|
38
43
|
end
|
|
39
44
|
|
|
40
45
|
# Resets the one-time boot guard. Intended for tests only.
|
|
@@ -60,6 +65,23 @@ module Dash0
|
|
|
60
65
|
)
|
|
61
66
|
end
|
|
62
67
|
|
|
68
|
+
def configure_from_file(path)
|
|
69
|
+
default_endpoint_from_collector_base_url
|
|
70
|
+
unless SdkConfiguration.apply_config_file(path)
|
|
71
|
+
Dash0::OpenTelemetry.log_debug("The SDK is disabled by the configuration file #{path}.")
|
|
72
|
+
return
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
InstrumentationInstaller.start
|
|
76
|
+
Lifecycle.install
|
|
77
|
+
Dash0::OpenTelemetry.log_debug("Distribution initialized (configuration file: #{path}).")
|
|
78
|
+
rescue StandardError, ScriptError => e
|
|
79
|
+
@booted = false
|
|
80
|
+
Dash0::OpenTelemetry.log_error(
|
|
81
|
+
"Initialization failed: #{e.message}. OpenTelemetry data will not be sent to Dash0."
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
63
85
|
def disabled?
|
|
64
86
|
return false unless Environment.opted_in?(DISABLE_ENV)
|
|
65
87
|
|
|
@@ -69,13 +91,14 @@ module Dash0
|
|
|
69
91
|
true
|
|
70
92
|
end
|
|
71
93
|
|
|
72
|
-
# The
|
|
73
|
-
#
|
|
94
|
+
# The collector base URL, or nil (with an explanatory log) when unset.
|
|
95
|
+
# There is no default in code - the operator supplies it.
|
|
74
96
|
def collector_base_url
|
|
75
97
|
value = ENV.fetch(COLLECTOR_BASE_URL_ENV, nil)
|
|
76
98
|
if value.nil? || value.strip.empty?
|
|
77
99
|
Dash0::OpenTelemetry.log_error(
|
|
78
|
-
"#{COLLECTOR_BASE_URL_ENV}
|
|
100
|
+
"Neither #{COLLECTOR_BASE_URL_ENV} nor #{CONFIG_FILE_ENV} is set, and #{DEFAULT_CONFIG_FILE} " \
|
|
101
|
+
'does not exist; there is nowhere to export to. ' \
|
|
79
102
|
'OpenTelemetry data will not be sent to Dash0.'
|
|
80
103
|
)
|
|
81
104
|
return nil
|
|
@@ -83,6 +106,26 @@ module Dash0
|
|
|
83
106
|
value.strip
|
|
84
107
|
end
|
|
85
108
|
|
|
109
|
+
# The declarative configuration file path: OTEL_CONFIG_FILE when set,
|
|
110
|
+
# otherwise +default_path+ when that file exists, otherwise nil. A set
|
|
111
|
+
# OTEL_CONFIG_FILE is used even if the file is missing, so the SDK reports
|
|
112
|
+
# the error instead of the distribution silently using another file.
|
|
113
|
+
def config_file_path(default_path = DEFAULT_CONFIG_FILE)
|
|
114
|
+
return ENV.fetch(CONFIG_FILE_ENV).strip if Environment.present?(CONFIG_FILE_ENV)
|
|
115
|
+
|
|
116
|
+
default_path if File.file?(default_path)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Defaults OTEL_EXPORTER_OTLP_ENDPOINT to the collector base URL, so a
|
|
120
|
+
# configuration file that interpolates it exports where the base URL
|
|
121
|
+
# points. Trailing slashes are dropped because files append signal paths.
|
|
122
|
+
def default_endpoint_from_collector_base_url
|
|
123
|
+
return unless Environment.present?(COLLECTOR_BASE_URL_ENV)
|
|
124
|
+
|
|
125
|
+
base_url = ENV.fetch(COLLECTOR_BASE_URL_ENV).strip.sub(%r{/+\z}, '')
|
|
126
|
+
Environment.set_default('OTEL_EXPORTER_OTLP_ENDPOINT', base_url)
|
|
127
|
+
end
|
|
128
|
+
|
|
86
129
|
# Detects whether OpenTelemetry's SDK was already loaded by the application
|
|
87
130
|
# (e.g. the app bundles and initializes OpenTelemetry itself). Checked
|
|
88
131
|
# before we require the SDK ourselves.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright 2026 Dash0 Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module Dash0
|
|
7
|
+
module OpenTelemetry
|
|
8
|
+
module DeclarativeConfig
|
|
9
|
+
# View builder for registering metric views from declarative config.
|
|
10
|
+
# A copy of the upstream opentelemetry-config implementation, used until a release includes it.
|
|
11
|
+
module MetricViews
|
|
12
|
+
INSTRUMENT_TYPES = %w[
|
|
13
|
+
counter gauge histogram observable_counter observable_gauge observable_up_down_counter up_down_counter
|
|
14
|
+
].freeze
|
|
15
|
+
MONOTONIC_INSTRUMENT_TYPES = %i[counter histogram observable_counter].freeze
|
|
16
|
+
private_constant :INSTRUMENT_TYPES, :MONOTONIC_INSTRUMENT_TYPES
|
|
17
|
+
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
# Registers a view on the meter provider from its selector and stream config.
|
|
21
|
+
def add_view(meter_provider, view_cfg)
|
|
22
|
+
selector = view_cfg.selector
|
|
23
|
+
stream = view_cfg.stream
|
|
24
|
+
raise ArgumentError, 'view requires a selector' unless selector
|
|
25
|
+
raise ArgumentError, 'view requires a stream' unless stream
|
|
26
|
+
|
|
27
|
+
type = build_instrument_type(selector.instrument_type)
|
|
28
|
+
Metrics.warn_unsupported('selector.meter_schema_url') if selector.meter_schema_url
|
|
29
|
+
Metrics.warn_unsupported('stream.name') if stream.name
|
|
30
|
+
Metrics.warn_unsupported('stream.description') if stream.description
|
|
31
|
+
Metrics.warn_unsupported('stream.attribute_keys') if stream.attribute_keys
|
|
32
|
+
|
|
33
|
+
opts = {
|
|
34
|
+
aggregation: build_aggregation(stream.aggregation, type),
|
|
35
|
+
type: type,
|
|
36
|
+
unit: selector.unit,
|
|
37
|
+
meter_name: selector.meter_name,
|
|
38
|
+
meter_version: selector.meter_version,
|
|
39
|
+
aggregation_cardinality_limit: stream.aggregation_cardinality_limit
|
|
40
|
+
}.compact
|
|
41
|
+
|
|
42
|
+
meter_provider.add_view(selector.instrument_name, **opts)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Converts a schema instrument type to the SDK instrument kind symbol.
|
|
46
|
+
def build_instrument_type(name)
|
|
47
|
+
return unless name
|
|
48
|
+
raise ArgumentError, "unknown instrument_type #{name}" unless INSTRUMENT_TYPES.include?(name)
|
|
49
|
+
|
|
50
|
+
name.to_sym
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Builds an SDK aggregation from config. A view without an SDK aggregation
|
|
54
|
+
# drops its data, so default resolves from the selected instrument type.
|
|
55
|
+
def build_aggregation(cfg, type)
|
|
56
|
+
a = ::OpenTelemetry::SDK::Metrics::Aggregation
|
|
57
|
+
|
|
58
|
+
if cfg&.drop
|
|
59
|
+
a::Drop.new
|
|
60
|
+
elsif cfg&.sum
|
|
61
|
+
a::Sum.new(monotonic: MONOTONIC_INSTRUMENT_TYPES.include?(type))
|
|
62
|
+
elsif cfg&.last_value
|
|
63
|
+
a::LastValue.new
|
|
64
|
+
elsif (hist = cfg&.explicit_bucket_histogram)
|
|
65
|
+
opts = { boundaries: hist.boundaries, record_min_max: hist.record_min_max }.compact
|
|
66
|
+
a::ExplicitBucketHistogram.new(**opts)
|
|
67
|
+
elsif (hist = cfg&.base2_exponential_bucket_histogram)
|
|
68
|
+
opts = { max_scale: hist.max_scale, max_size: hist.max_size, record_min_max: hist.record_min_max }.compact
|
|
69
|
+
a::ExponentialBucketHistogram.new(**opts)
|
|
70
|
+
else
|
|
71
|
+
build_default_aggregation(type)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Returns the aggregation the SDK instrument of the given type uses by default.
|
|
76
|
+
def build_default_aggregation(type)
|
|
77
|
+
a = ::OpenTelemetry::SDK::Metrics::Aggregation
|
|
78
|
+
|
|
79
|
+
case type
|
|
80
|
+
when :counter then a::Sum.new(monotonic: true)
|
|
81
|
+
when :observable_counter then a::Sum.new(monotonic: true, instrument_kind: type)
|
|
82
|
+
when :up_down_counter, :observable_up_down_counter
|
|
83
|
+
a::Sum.new(aggregation_temporality: :cumulative, monotonic: false)
|
|
84
|
+
when :histogram then a::ExplicitBucketHistogram.new
|
|
85
|
+
when :gauge, :observable_gauge then a::LastValue.new
|
|
86
|
+
else raise ArgumentError, 'default aggregation requires selector.instrument_type'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright 2026 Dash0 Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module Dash0
|
|
7
|
+
module OpenTelemetry
|
|
8
|
+
module DeclarativeConfig
|
|
9
|
+
# Metrics component builder for configuring MeterProvider from declarative config.
|
|
10
|
+
# A copy of the upstream opentelemetry-config implementation, used until a release includes it.
|
|
11
|
+
module Metrics
|
|
12
|
+
PER_KIND_CARDINALITY_LIMITS = %i[
|
|
13
|
+
counter gauge histogram observable_counter observable_gauge observable_up_down_counter up_down_counter
|
|
14
|
+
].freeze
|
|
15
|
+
private_constant :PER_KIND_CARDINALITY_LIMITS
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# Builds a MeterProvider from the parsed YAML meter_provider config.
|
|
20
|
+
# Returns nil if config is nil or opentelemetry-metrics-sdk isn't loaded.
|
|
21
|
+
def build_meter_provider(config, resource)
|
|
22
|
+
return unless config
|
|
23
|
+
|
|
24
|
+
unless defined?(::OpenTelemetry::SDK::Metrics::MeterProvider)
|
|
25
|
+
::OpenTelemetry.logger.warn('meter_provider is configured but opentelemetry-metrics-sdk is not loaded. ' \
|
|
26
|
+
'Add `gem "opentelemetry-metrics-sdk"` to your Gemfile.')
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
mp = ::OpenTelemetry::SDK::Metrics::MeterProvider.new(resource: resource)
|
|
31
|
+
exemplar_filter = build_exemplar_filter(config.exemplar_filter)
|
|
32
|
+
mp.enable_exemplar_filter(exemplar_filter: exemplar_filter) if exemplar_filter
|
|
33
|
+
|
|
34
|
+
Array(config.views).each do |view_cfg|
|
|
35
|
+
MetricViews.add_view(mp, view_cfg)
|
|
36
|
+
rescue StandardError => e
|
|
37
|
+
::OpenTelemetry.logger.warn("Failed to build view: #{e.message}")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
Array(config.readers).each do |reader_cfg|
|
|
41
|
+
mp.add_metric_reader(build_metric_reader(reader_cfg))
|
|
42
|
+
rescue StandardError => e
|
|
43
|
+
::OpenTelemetry.logger.warn("Failed to build metric reader: #{e.message}")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
mp
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Builds a metric reader from config; only periodic readers are supported.
|
|
50
|
+
def build_metric_reader(reader_cfg)
|
|
51
|
+
raise ArgumentError, 'must not specify multiple metric reader types' if reader_cfg.periodic && reader_cfg.pull
|
|
52
|
+
raise ArgumentError, 'pull metric readers are not supported' if reader_cfg.pull
|
|
53
|
+
raise ArgumentError, 'unsupported metric reader type, must be periodic' unless reader_cfg.periodic
|
|
54
|
+
|
|
55
|
+
build_periodic_metric_reader(reader_cfg.periodic)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Builds a PeriodicMetricReader with exporter and optional tuning options.
|
|
59
|
+
def build_periodic_metric_reader(cfg)
|
|
60
|
+
warn_unsupported('producers') unless Array(cfg.producers).empty?
|
|
61
|
+
|
|
62
|
+
exporter = build_metric_exporter(cfg.exporter)
|
|
63
|
+
opts = {
|
|
64
|
+
export_interval_millis: cfg.interval&.to_f,
|
|
65
|
+
export_timeout_millis: cfg.timeout&.to_f,
|
|
66
|
+
aggregation_cardinality_limit: build_cardinality_limit(cfg.cardinality_limits)
|
|
67
|
+
}.compact
|
|
68
|
+
|
|
69
|
+
::OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(exporter: exporter, **opts)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Builds a push metric exporter from config; supports console and otlp_http.
|
|
73
|
+
def build_metric_exporter(exp_cfg)
|
|
74
|
+
raise ArgumentError, 'no exporter config' unless exp_cfg
|
|
75
|
+
raise ArgumentError, 'otlp_grpc metric exporter is not supported' if exp_cfg.otlp_grpc
|
|
76
|
+
raise ArgumentError, 'otlp_file/development metric exporter is not supported' if exp_cfg.otlp_file_development
|
|
77
|
+
|
|
78
|
+
configured = 0
|
|
79
|
+
exporter = nil
|
|
80
|
+
|
|
81
|
+
if exp_cfg.console
|
|
82
|
+
configured += 1
|
|
83
|
+
warn_unsupported_exporter_options(exp_cfg.console)
|
|
84
|
+
exporter = ::OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter.new
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
if exp_cfg.otlp_http
|
|
88
|
+
configured += 1
|
|
89
|
+
warn_unsupported_exporter_options(exp_cfg.otlp_http)
|
|
90
|
+
exporter = build_otlp_http_metric_exporter(exp_cfg.otlp_http)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
raise ArgumentError, 'must not specify multiple exporters' if configured > 1
|
|
94
|
+
raise ArgumentError, 'no valid metric exporter' if exporter.nil?
|
|
95
|
+
|
|
96
|
+
exporter
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Builds an OTLP HTTP metric exporter from the given endpoint, headers, and TLS config.
|
|
100
|
+
def build_otlp_http_metric_exporter(cfg)
|
|
101
|
+
unless defined?(::OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter)
|
|
102
|
+
raise ArgumentError, 'otlp_http requires opentelemetry-exporter-otlp-metrics. ' \
|
|
103
|
+
'Add `gem "opentelemetry-exporter-otlp-metrics"` to your Gemfile.'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
warn_unsupported('encoding: json') if cfg.encoding == 'json'
|
|
107
|
+
|
|
108
|
+
headers = headers_to_hash(cfg)
|
|
109
|
+
opts = {
|
|
110
|
+
endpoint: cfg.endpoint,
|
|
111
|
+
certificate_file: cfg.tls&.ca_file,
|
|
112
|
+
client_certificate_file: cfg.tls&.cert_file,
|
|
113
|
+
client_key_file: cfg.tls&.key_file,
|
|
114
|
+
headers: headers.empty? ? nil : headers,
|
|
115
|
+
compression: cfg.compression,
|
|
116
|
+
timeout: cfg.timeout && (cfg.timeout / 1000.0)
|
|
117
|
+
}.compact
|
|
118
|
+
|
|
119
|
+
::OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new(**opts)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Returns exporter headers from +headers+, or from +headers_list+ when
|
|
123
|
+
# +headers+ is empty.
|
|
124
|
+
def headers_to_hash(cfg)
|
|
125
|
+
headers = {}
|
|
126
|
+
|
|
127
|
+
Array(cfg.headers).each do |pair|
|
|
128
|
+
headers[pair.name] = pair.value if pair&.name
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
if headers.empty? && cfg.headers_list.is_a?(String)
|
|
132
|
+
cfg.headers_list.split(',').each do |entry|
|
|
133
|
+
key, value = entry.strip.split('=', 2)
|
|
134
|
+
headers[key] = value if key && value
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
headers
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Warns about exporter options the metrics SDK can't apply per reader.
|
|
142
|
+
def warn_unsupported_exporter_options(cfg)
|
|
143
|
+
warn_unsupported('temporality_preference') if cfg.temporality_preference
|
|
144
|
+
warn_unsupported('default_histogram_aggregation') if cfg.default_histogram_aggregation
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Returns the reader-wide cardinality limit. The SDK applies one limit per
|
|
148
|
+
# reader, so per-instrument-kind limits are ignored.
|
|
149
|
+
def build_cardinality_limit(cfg)
|
|
150
|
+
return unless cfg
|
|
151
|
+
|
|
152
|
+
PER_KIND_CARDINALITY_LIMITS.each { |kind| warn_unsupported("cardinality_limits.#{kind}") if cfg[kind] }
|
|
153
|
+
|
|
154
|
+
cfg.default
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Logs that a configured meter_provider setting has no effect.
|
|
158
|
+
def warn_unsupported(setting)
|
|
159
|
+
::OpenTelemetry.logger.warn("Ignoring unsupported meter_provider setting: #{setting}")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Returns the exemplar filter for the configured name, or nil when unset or unknown.
|
|
163
|
+
def build_exemplar_filter(name)
|
|
164
|
+
e = ::OpenTelemetry::SDK::Metrics::Exemplar
|
|
165
|
+
|
|
166
|
+
case name
|
|
167
|
+
when nil then nil
|
|
168
|
+
when 'trace_based' then e::TraceBasedExemplarFilter
|
|
169
|
+
when 'always_on' then e::AlwaysOnExemplarFilter
|
|
170
|
+
when 'always_off' then e::AlwaysOffExemplarFilter
|
|
171
|
+
else
|
|
172
|
+
::OpenTelemetry.logger.warn("Unknown exemplar_filter #{name}. Ignoring.")
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright 2026 Dash0 Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module Dash0
|
|
7
|
+
module OpenTelemetry
|
|
8
|
+
module DeclarativeConfig
|
|
9
|
+
# Lets a configuration file name the Dash0 resource detectors, e.g.
|
|
10
|
+
#
|
|
11
|
+
# resource:
|
|
12
|
+
# detection/development:
|
|
13
|
+
# detectors:
|
|
14
|
+
# - dash0_distribution: {}
|
|
15
|
+
# - dash0_kubernetes: {}
|
|
16
|
+
# - dash0_service_name: {}
|
|
17
|
+
#
|
|
18
|
+
# opentelemetry-config has no extension point for detectors and warns about
|
|
19
|
+
# names it does not know, so this patches its private resource builders.
|
|
20
|
+
# The patch is skipped if those builders change.
|
|
21
|
+
module ResourceDetectors
|
|
22
|
+
SERVICE_NAME_DETECTOR = 'dash0_service_name'
|
|
23
|
+
DEFAULT_SERVICE_NAME = 'unknown_service'
|
|
24
|
+
DETECTORS = {
|
|
25
|
+
'dash0_distribution' => Resource::Distribution,
|
|
26
|
+
'dash0_kubernetes' => Resource::KubernetesPod
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
# Prepended to the singleton class of OpenTelemetry::Config.
|
|
30
|
+
module ConfigPatch
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# The service name fallback runs in build_resource, after the file's
|
|
34
|
+
# own attributes are known.
|
|
35
|
+
def run_detector(name)
|
|
36
|
+
return DETECTORS.fetch(name).detect if DETECTORS.key?(name)
|
|
37
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({}) if name == SERVICE_NAME_DETECTOR
|
|
38
|
+
|
|
39
|
+
super
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Applies the service name fallback when the file names it and does not
|
|
43
|
+
# set a service name of its own.
|
|
44
|
+
def build_resource(resource_cfg)
|
|
45
|
+
resource = super
|
|
46
|
+
return resource unless ResourceDetectors.service_name_requested?(resource_cfg)
|
|
47
|
+
|
|
48
|
+
service_name = resource.attribute_enumerator.to_h['service.name']
|
|
49
|
+
return resource unless service_name.nil? || service_name == DEFAULT_SERVICE_NAME
|
|
50
|
+
|
|
51
|
+
resource.merge(Resource::ServiceNameFallback.detect(declarative: true))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
module_function
|
|
56
|
+
|
|
57
|
+
# Patches opentelemetry-config to run the Dash0 detectors. Safe to repeat.
|
|
58
|
+
def install
|
|
59
|
+
config = ::OpenTelemetry::Config.singleton_class
|
|
60
|
+
unless %i[run_detector build_resource].all? { |name| config.private_method_defined?(name) }
|
|
61
|
+
Dash0::OpenTelemetry.log_error(
|
|
62
|
+
'The installed opentelemetry-config is not supported by the Dash0 resource detectors. ' \
|
|
63
|
+
'Configuration files cannot use dash0_distribution, dash0_kubernetes, or dash0_service_name.'
|
|
64
|
+
)
|
|
65
|
+
return
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
config.prepend(ConfigPatch)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Whether the file names the service name fallback detector.
|
|
72
|
+
def service_name_requested?(resource_cfg)
|
|
73
|
+
Array(resource_cfg&.detection_development&.detectors).any? do |detector|
|
|
74
|
+
detector&.additional_properties&.key?(SERVICE_NAME_DETECTOR)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright 2026 Dash0 Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require 'dash0/opentelemetry/declarative_config/metrics'
|
|
7
|
+
require 'dash0/opentelemetry/declarative_config/metric_views'
|
|
8
|
+
require 'dash0/opentelemetry/declarative_config/resource_detectors'
|
|
9
|
+
|
|
10
|
+
module Dash0
|
|
11
|
+
module OpenTelemetry
|
|
12
|
+
# Wraps opentelemetry-config to support declarative configuration it does
|
|
13
|
+
# not support yet. Each gap is filled only when upstream leaves it empty, so
|
|
14
|
+
# the copies here become unused as upstream releases them, and can be deleted.
|
|
15
|
+
module DeclarativeConfig
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# Creates the SDK components described by a configuration model, adding the
|
|
19
|
+
# providers opentelemetry-config does not build yet.
|
|
20
|
+
#
|
|
21
|
+
# @param model [OpenTelemetry::Config::Model::OpenTelemetryConfiguration]
|
|
22
|
+
# @return [OpenTelemetry::Config::RubySDK]
|
|
23
|
+
def create(model)
|
|
24
|
+
sdk = ::OpenTelemetry::Config.create(model)
|
|
25
|
+
return sdk if sdk.equal?(::OpenTelemetry::Config::NOOP_SDK)
|
|
26
|
+
|
|
27
|
+
sdk.meter_provider ||= Metrics.build_meter_provider(model.meter_provider, sdk.resource)
|
|
28
|
+
sdk
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Installs the SDK components as the global OpenTelemetry state, including
|
|
32
|
+
# the providers opentelemetry-config does not install yet.
|
|
33
|
+
#
|
|
34
|
+
# @param sdk [OpenTelemetry::Config::RubySDK]
|
|
35
|
+
# @return [OpenTelemetry::Config::RubySDK] the same SDK handle
|
|
36
|
+
def install(sdk)
|
|
37
|
+
return sdk if sdk.equal?(::OpenTelemetry::Config::NOOP_SDK)
|
|
38
|
+
|
|
39
|
+
::OpenTelemetry::Config.install(sdk)
|
|
40
|
+
install_meter_provider(sdk.meter_provider) if sdk.meter_provider
|
|
41
|
+
sdk
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Installs the meter provider as the global and restarts its periodic
|
|
45
|
+
# readers in forked child processes. Safe to repeat.
|
|
46
|
+
def install_meter_provider(provider)
|
|
47
|
+
::OpenTelemetry.meter_provider = provider
|
|
48
|
+
::OpenTelemetry::SDK::Metrics::ForkHooks.attach!
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -28,6 +28,11 @@ module Dash0
|
|
|
28
28
|
# `OTEL_SERVICE_NAME` or a `service.name` in `OTEL_RESOURCE_ATTRIBUTES`, or
|
|
29
29
|
# when opted out with `DASH0_AUTOMATIC_SERVICE_NAME=false`.
|
|
30
30
|
#
|
|
31
|
+
# When a configuration file names this detector, the caller applies it only
|
|
32
|
+
# if the file produces no service name. `OTEL_SERVICE_NAME` is then used if
|
|
33
|
+
# set, and `OTEL_RESOURCE_ATTRIBUTES` is not consulted, since it only applies
|
|
34
|
+
# under a configuration file through the file's own references.
|
|
35
|
+
#
|
|
31
36
|
# `OpenTelemetry::SDK` must be loaded before `detect` is called.
|
|
32
37
|
module ServiceNameFallback
|
|
33
38
|
AUTOMATIC_SERVICE_NAME_ENV = 'DASH0_AUTOMATIC_SERVICE_NAME'
|
|
@@ -58,9 +63,11 @@ module Dash0
|
|
|
58
63
|
extend self
|
|
59
64
|
|
|
60
65
|
# The detector interface: the only public method.
|
|
61
|
-
|
|
66
|
+
#
|
|
67
|
+
# @param declarative [Boolean] whether a configuration file names this detector
|
|
68
|
+
def detect(declarative: false)
|
|
62
69
|
attributes = {}
|
|
63
|
-
name = fallback_service_name
|
|
70
|
+
name = declarative ? declarative_service_name : fallback_service_name
|
|
64
71
|
attributes[SERVICE_NAME_KEY] = name if name
|
|
65
72
|
::OpenTelemetry::SDK::Resources::Resource.create(attributes)
|
|
66
73
|
end
|
|
@@ -75,6 +82,15 @@ module Dash0
|
|
|
75
82
|
name_from_project(root) || derive_from_program_name(program_name)
|
|
76
83
|
end
|
|
77
84
|
|
|
85
|
+
# @return [String, nil] `OTEL_SERVICE_NAME` when set, otherwise the derived
|
|
86
|
+
# service name, or nil when the fallback is opted out or none can be derived.
|
|
87
|
+
def declarative_service_name(program_name = $PROGRAM_NAME, root = app_root)
|
|
88
|
+
return ENV.fetch('OTEL_SERVICE_NAME').strip if otel_service_name_set?
|
|
89
|
+
return nil if opted_out?
|
|
90
|
+
|
|
91
|
+
name_from_project(root) || derive_from_program_name(program_name)
|
|
92
|
+
end
|
|
93
|
+
|
|
78
94
|
def name_from_project(root)
|
|
79
95
|
return nil unless root
|
|
80
96
|
|
|
@@ -19,6 +19,13 @@ module Dash0
|
|
|
19
19
|
# OTLP is only supported over HTTP/protobuf in the Ruby SDK's default path.
|
|
20
20
|
DEFAULT_PROTOCOL = 'http/protobuf'
|
|
21
21
|
|
|
22
|
+
# Applied when OTEL_PROPAGATORS is unset. X-Ray comes after tracecontext so that,
|
|
23
|
+
# when a request carries both headers, the X-Ray context wins; an X-Ray header
|
|
24
|
+
# without a Parent (as an ALB adds) fails to extract and keeps the
|
|
25
|
+
# tracecontext result.
|
|
26
|
+
DEFAULT_PROPAGATORS = 'tracecontext,baggage,xray'
|
|
27
|
+
PROPAGATORS_ENV = 'OTEL_PROPAGATORS'
|
|
28
|
+
|
|
22
29
|
# DASH0_DEBUG_PRINT_SPANS=true additionally prints every span to stdout.
|
|
23
30
|
DEBUG_PRINT_SPANS_ENV = 'DASH0_DEBUG_PRINT_SPANS'
|
|
24
31
|
|
|
@@ -44,22 +51,53 @@ module Dash0
|
|
|
44
51
|
# `OTEL_EXPORTER_OTLP_ENDPOINT` is used (not a signal-specific variable),
|
|
45
52
|
# so each exporter appends its own `/v1/{traces,metrics,logs}` path.
|
|
46
53
|
def apply(base_url:)
|
|
47
|
-
|
|
54
|
+
configure_env_defaults(base_url)
|
|
48
55
|
require_sdk_gems
|
|
49
56
|
resource = build_resource
|
|
50
57
|
|
|
51
58
|
::OpenTelemetry::SDK.configure do |c|
|
|
52
59
|
c.resource = resource
|
|
60
|
+
c.propagators = default_propagators unless Environment.present?(PROPAGATORS_ENV)
|
|
53
61
|
end
|
|
54
62
|
|
|
55
63
|
install_debug_span_printer if Environment.opted_in?(DEBUG_PRINT_SPANS_ENV)
|
|
56
64
|
end
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
# Configures the SDK from a declarative configuration file. The file is the
|
|
67
|
+
# complete SDK configuration, so the env-driven defaults, the Dash0 resource,
|
|
68
|
+
# and the debug span printer do not apply.
|
|
69
|
+
#
|
|
70
|
+
# @param path [String] path to the declarative configuration file
|
|
71
|
+
# @return [OpenTelemetry::Config::RubySDK, nil] the installed SDK, or nil
|
|
72
|
+
# when the file disables it
|
|
73
|
+
# @raise [StandardError] when the file cannot be loaded
|
|
74
|
+
def apply_config_file(path)
|
|
75
|
+
require_sdk_gems
|
|
76
|
+
require 'opentelemetry-config'
|
|
77
|
+
DeclarativeConfig::ResourceDetectors.install
|
|
78
|
+
|
|
79
|
+
model = ::OpenTelemetry::Config.parse(path)
|
|
80
|
+
raise "could not load the configuration file #{path}" unless model
|
|
81
|
+
|
|
82
|
+
sdk = DeclarativeConfig.install(DeclarativeConfig.create(model))
|
|
83
|
+
sdk unless sdk.equal?(::OpenTelemetry::Config::NOOP_SDK)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def configure_env_defaults(base_url)
|
|
59
87
|
Environment.set_default('OTEL_EXPORTER_OTLP_ENDPOINT', base_url)
|
|
60
88
|
Environment.set_default('OTEL_EXPORTER_OTLP_PROTOCOL', DEFAULT_PROTOCOL)
|
|
61
89
|
end
|
|
62
90
|
|
|
91
|
+
# The DEFAULT_PROPAGATORS instances. Set on the configurator rather than in
|
|
92
|
+
# ENV so child processes, which may lack an X-Ray propagator, don't inherit it.
|
|
93
|
+
def default_propagators
|
|
94
|
+
[
|
|
95
|
+
::OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator,
|
|
96
|
+
::OpenTelemetry::Baggage::Propagation.text_map_propagator,
|
|
97
|
+
::OpenTelemetry::Propagator::XRay.text_map_propagator
|
|
98
|
+
]
|
|
99
|
+
end
|
|
100
|
+
|
|
63
101
|
def require_sdk_gems
|
|
64
102
|
wire_additional_gem_path
|
|
65
103
|
require 'opentelemetry-sdk'
|
|
@@ -68,6 +106,7 @@ module Dash0
|
|
|
68
106
|
require 'opentelemetry-exporter-otlp'
|
|
69
107
|
require 'opentelemetry-exporter-otlp-metrics'
|
|
70
108
|
require 'opentelemetry-exporter-otlp-logs'
|
|
109
|
+
require 'opentelemetry-propagator-xray'
|
|
71
110
|
require 'opentelemetry-resource-detector-container'
|
|
72
111
|
# Populate the instrumentation registry so the installer can sweep it.
|
|
73
112
|
require 'opentelemetry-instrumentation-all'
|
data/lib/dash0/opentelemetry.rb
CHANGED
|
@@ -8,6 +8,7 @@ require 'dash0/opentelemetry/environment'
|
|
|
8
8
|
require 'dash0/opentelemetry/resource/distribution'
|
|
9
9
|
require 'dash0/opentelemetry/resource/kubernetes_pod'
|
|
10
10
|
require 'dash0/opentelemetry/resource/service_name_fallback'
|
|
11
|
+
require 'dash0/opentelemetry/declarative_config'
|
|
11
12
|
require 'dash0/opentelemetry/instrumentation_installer'
|
|
12
13
|
require 'dash0/opentelemetry/lifecycle'
|
|
13
14
|
require 'dash0/opentelemetry/sdk_configuration'
|
metadata
CHANGED
|
@@ -1,127 +1,155 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dash0-opentelemetry
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dash0 Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: opentelemetry-config
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.2.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.2.0
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: opentelemetry-exporter-otlp
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
16
30
|
requirements:
|
|
17
31
|
- - "~>"
|
|
18
32
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
33
|
+
version: 0.37.0
|
|
20
34
|
type: :runtime
|
|
21
35
|
prerelease: false
|
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
37
|
requirements:
|
|
24
38
|
- - "~>"
|
|
25
39
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
40
|
+
version: 0.37.0
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: opentelemetry-exporter-otlp-logs
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
30
44
|
requirements:
|
|
31
45
|
- - "~>"
|
|
32
46
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.
|
|
47
|
+
version: 0.7.0
|
|
34
48
|
type: :runtime
|
|
35
49
|
prerelease: false
|
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
51
|
requirements:
|
|
38
52
|
- - "~>"
|
|
39
53
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.
|
|
54
|
+
version: 0.7.0
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: opentelemetry-exporter-otlp-metrics
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
44
58
|
requirements:
|
|
45
59
|
- - "~>"
|
|
46
60
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
61
|
+
version: 0.14.0
|
|
48
62
|
type: :runtime
|
|
49
63
|
prerelease: false
|
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
65
|
requirements:
|
|
52
66
|
- - "~>"
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
68
|
+
version: 0.14.0
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: opentelemetry-instrumentation-all
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
58
72
|
requirements:
|
|
59
73
|
- - "~>"
|
|
60
74
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 0.
|
|
75
|
+
version: 0.99.0
|
|
62
76
|
type: :runtime
|
|
63
77
|
prerelease: false
|
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
79
|
requirements:
|
|
66
80
|
- - "~>"
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 0.
|
|
82
|
+
version: 0.99.0
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
84
|
name: opentelemetry-logs-sdk
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
72
86
|
requirements:
|
|
73
87
|
- - "~>"
|
|
74
88
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.
|
|
89
|
+
version: 0.8.1
|
|
76
90
|
type: :runtime
|
|
77
91
|
prerelease: false
|
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
93
|
requirements:
|
|
80
94
|
- - "~>"
|
|
81
95
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.
|
|
96
|
+
version: 0.8.1
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: opentelemetry-metrics-sdk
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
|
86
100
|
requirements:
|
|
87
101
|
- - "~>"
|
|
88
102
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.
|
|
103
|
+
version: 0.21.0
|
|
90
104
|
type: :runtime
|
|
91
105
|
prerelease: false
|
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
107
|
requirements:
|
|
94
108
|
- - "~>"
|
|
95
109
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.
|
|
110
|
+
version: 0.21.0
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: opentelemetry-propagator-xray
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 0.27.0
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 0.27.0
|
|
97
125
|
- !ruby/object:Gem::Dependency
|
|
98
126
|
name: opentelemetry-resource-detector-container
|
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
|
100
128
|
requirements:
|
|
101
129
|
- - "~>"
|
|
102
130
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: 0.
|
|
131
|
+
version: 0.4.0
|
|
104
132
|
type: :runtime
|
|
105
133
|
prerelease: false
|
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
135
|
requirements:
|
|
108
136
|
- - "~>"
|
|
109
137
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: 0.
|
|
138
|
+
version: 0.4.0
|
|
111
139
|
- !ruby/object:Gem::Dependency
|
|
112
140
|
name: opentelemetry-sdk
|
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
|
114
142
|
requirements:
|
|
115
143
|
- - "~>"
|
|
116
144
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: 1.
|
|
145
|
+
version: 1.13.1
|
|
118
146
|
type: :runtime
|
|
119
147
|
prerelease: false
|
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
149
|
requirements:
|
|
122
150
|
- - "~>"
|
|
123
151
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 1.
|
|
152
|
+
version: 1.13.1
|
|
125
153
|
description: An opinionated, zero-code OpenTelemetry distribution for Ruby that wraps
|
|
126
154
|
upstream OpenTelemetry and is designed to be injected by the Dash0 Kubernetes operator.
|
|
127
155
|
email:
|
|
@@ -131,6 +159,7 @@ extensions: []
|
|
|
131
159
|
extra_rdoc_files: []
|
|
132
160
|
files:
|
|
133
161
|
- CHANGELOG.md
|
|
162
|
+
- CLAUDE.md
|
|
134
163
|
- CONTRIBUTING.md
|
|
135
164
|
- LICENSE
|
|
136
165
|
- README.md
|
|
@@ -138,6 +167,10 @@ files:
|
|
|
138
167
|
- lib/dash0-opentelemetry.rb
|
|
139
168
|
- lib/dash0/opentelemetry.rb
|
|
140
169
|
- lib/dash0/opentelemetry/boot.rb
|
|
170
|
+
- lib/dash0/opentelemetry/declarative_config.rb
|
|
171
|
+
- lib/dash0/opentelemetry/declarative_config/metric_views.rb
|
|
172
|
+
- lib/dash0/opentelemetry/declarative_config/metrics.rb
|
|
173
|
+
- lib/dash0/opentelemetry/declarative_config/resource_detectors.rb
|
|
141
174
|
- lib/dash0/opentelemetry/environment.rb
|
|
142
175
|
- lib/dash0/opentelemetry/instrumentation_installer.rb
|
|
143
176
|
- lib/dash0/opentelemetry/lifecycle.rb
|