Skip to content

Commit 3023fc3

Browse files
committed
feat: configure TLS with environment variables.
Updates the opentelemetry-otlp crate to allow users to configure TLS using environment variables. Removing the need to crating the TLS config object and defining it with the `with_tls_config` method. In the same way other OTLP libraries does (e.g. go lang). Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
1 parent 130e178 commit 3023fc3

File tree

10 files changed

+699
-84
lines changed

10 files changed

+699
-84
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tokio-stream = "0.1"
4949
# required for OpenTelemetry's internal logging macros.
5050
tracing = { version = ">=0.1.40", default-features = false }
5151
# `tracing-core >=0.1.33` is required for compatibility with `tracing >=0.1.40`.
52-
tracing-core = { version = ">=0.1.33", default-features = false }
52+
tracing-core = { version = ">=0.1.33", default-features = false }
5353
tracing-subscriber = { version = "0.3", default-features = false }
5454
url = { version = "2.5", default-features = false }
5555
anyhow = "1.0.94"
@@ -71,12 +71,13 @@ percent-encoding = "2.0"
7171
rstest = "0.23.0"
7272
schemars = "0.8"
7373
sysinfo = "0.32"
74-
tempfile = "3.3.0"
7574
testcontainers = "0.23.1"
7675
tracing-log = "0.2"
7776
tracing-opentelemetry = "0.30"
7877
typed-builder = "0.20"
7978
uuid = "1.3"
79+
rcgen = { version = "0.13", features = ["crypto"] }
80+
tempfile = "3.14"
8081

8182
# Aviod use of crates.io version of these crates through the tracing-opentelemetry dependencies
8283
[patch.crates-io]

opentelemetry-otlp/CHANGELOG.md

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## vNext
44

55
- Update `tonic` dependency version to 0.13
6+
- TLS configuration via environment variables for GRPc exporters.
67

78
## 0.29.0
89

@@ -19,16 +20,16 @@ Released 2025-Mar-21
1920
[#2770](https://github.com/open-telemetry/opentelemetry-rust/issues/2770)
2021
partially to properly handle `shutdown()` when using `http`. (`tonic` still
2122
does not do proper shutdown)
22-
- *Breaking*
23-
ExporterBuilder's build() method now Result with `ExporterBuildError` being the
24-
Error variant. Previously it returned signal specific errors like `LogError`
25-
from the `opentelemetry_sdk`, which are no longer part of the sdk. No changes
26-
required if you were using unwrap/expect. If you were matching on the returning
27-
Error enum, replace with the enum `ExporterBuildError`. Unlike the previous
28-
`Error` which contained many variants unrelated to building an exporter, the
29-
new one returns specific variants applicable to building an exporter. Some
30-
variants might be applicable only on select features.
31-
Also, now unused `Error` enum is removed.
23+
- _Breaking_
24+
ExporterBuilder's build() method now Result with `ExporterBuildError` being the
25+
Error variant. Previously it returned signal specific errors like `LogError`
26+
from the `opentelemetry_sdk`, which are no longer part of the sdk. No changes
27+
required if you were using unwrap/expect. If you were matching on the returning
28+
Error enum, replace with the enum `ExporterBuildError`. Unlike the previous
29+
`Error` which contained many variants unrelated to building an exporter, the
30+
new one returns specific variants applicable to building an exporter. Some
31+
variants might be applicable only on select features.
32+
Also, now unused `Error` enum is removed.
3233
- **Breaking** `ExportConfig`'s `timeout` field is now optional(`Option<Duration>`)
3334
- **Breaking** Export configuration done via code is final. ENV variables cannot be used to override the code config.
3435
Do not use code based config, if there is desire to control the settings via ENV variables.
@@ -58,10 +59,10 @@ Released 2025-Feb-10
5859
- The HTTP clients (reqwest, reqwest-blocking, hyper) now support the
5960
export timeout interval configured in below order
6061
- Signal specific env variable `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`,
61-
`OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` or `OTEL_EXPORTER_OTLP_TIMEOUT`.
62+
`OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` or `OTEL_EXPORTER_OTLP_TIMEOUT`.
6263
- `OTEL_EXPORTER_OTLP_TIMEOUT` env variable.
6364
- `with_http().with_timeout()` API method of
64-
`LogExporterBuilder` and `SpanExporterBuilder` and `MetricsExporterBuilder`.
65+
`LogExporterBuilder` and `SpanExporterBuilder` and `MetricsExporterBuilder`.
6566
- The default interval of 10 seconds is used if none is configured.
6667

6768
## 0.27.0
@@ -74,6 +75,7 @@ Released 2024-Nov-11
7475
- Update `opentelemetry-proto` dependency version to 0.27
7576

7677
- **BREAKING**:
78+
7779
- ([#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)) **Replaced**: The `MetricsExporterBuilder` interface is modified from `with_temporality_selector` to `with_temporality` example can be seen below:
7880
Previous Signature:
7981
```rust
@@ -84,13 +86,15 @@ Released 2024-Nov-11
8486
MetricsExporterBuilder::default().with_temporality(opentelemetry_sdk::metrics::Temporality::Delta)
8587
```
8688
- ([#2221](https://github.com/open-telemetry/opentelemetry-rust/pull/2221)) **Replaced**:
89+
8790
- The `opentelemetry_otlp::new_pipeline().{trace,logging,metrics}()` interface is now replaced with `{TracerProvider,SdkMeterProvider,LoggerProvider}::builder()`.
8891
- The `opentelemetry_otlp::new_exporter()` interface is now replaced with `{SpanExporter,MetricsExporter,LogExporter}::builder()`.
8992

9093
Pull request [#2221](https://github.com/open-telemetry/opentelemetry-rust/pull/2221) has a detailed migration guide in the description. See example below,
9194
and [basic-otlp](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp/src/main.rs) for more details:
9295

9396
Previous Signature:
97+
9498
```rust
9599
let logger_provider: LoggerProvider = opentelemetry_otlp::new_pipeline()
96100
.logging()
@@ -102,7 +106,9 @@ Released 2024-Nov-11
102106
)
103107
.install_batch(runtime::Tokio)?;
104108
```
109+
105110
Updated Signature:
111+
106112
```rust
107113
let exporter = LogExporter::builder()
108114
.with_tonic()
@@ -114,16 +120,19 @@ Released 2024-Nov-11
114120
.with_batch_exporter(exporter, runtime::Tokio)
115121
.build())
116122
```
123+
117124
- **Renamed**
125+
118126
- ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types.
119127
- `MetricsExporter` -> `MetricExporter`
120128
- `MetricsExporterBuilder` -> `MetricExporterBuilder`
121129

122130
- [#2263](https://github.com/open-telemetry/opentelemetry-rust/pull/2263)
123-
Support `hyper` client for opentelemetry-otlp. This can be enabled using flag `hyper-client`.
124-
Refer example: https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/examples/basic-otlp-http
131+
Support `hyper` client for opentelemetry-otlp. This can be enabled using flag `hyper-client`.
132+
Refer example: https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/examples/basic-otlp-http
125133

126134
## v0.26.0
135+
127136
Released 2024-Sep-30
128137

129138
- Update `opentelemetry` dependency version to 0.26
@@ -141,11 +150,11 @@ Released 2024-Sep-30
141150
- Starting with this version, this crate will align with `opentelemetry` crate
142151
on major,minor versions.
143152
- **Breaking**
144-
The logrecord event-name is added as an attribute only if the feature flag
145-
`populate-logs-event-name` is enabled. The name of the attribute is changed from
146-
"name" to "event.name".
147-
[1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994),
148-
[2050](https://github.com/open-telemetry/opentelemetry-rust/pull/2050)
153+
The logrecord event-name is added as an attribute only if the feature flag
154+
`populate-logs-event-name` is enabled. The name of the attribute is changed from
155+
"name" to "event.name".
156+
[1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994),
157+
[2050](https://github.com/open-telemetry/opentelemetry-rust/pull/2050)
149158

150159
## v0.17.0
151160

@@ -155,10 +164,10 @@ The logrecord event-name is added as an attribute only if the feature flag
155164
`global::set_meter_provider`. User who setup the pipeline must do it
156165
themselves using `global::set_meter_provider(meter_provider.clone());`.
157166
- Add `with_resource` on `OtlpLogPipeline`, replacing the `with_config` method.
158-
Instead of using
159-
`.with_config(Config::default().with_resource(RESOURCE::default()))` users must
160-
now use `.with_resource(RESOURCE::default())` to configure Resource when using
161-
`OtlpLogPipeline`.
167+
Instead of using
168+
`.with_config(Config::default().with_resource(RESOURCE::default()))` users must
169+
now use `.with_resource(RESOURCE::default())` to configure Resource when using
170+
`OtlpLogPipeline`.
162171
- **Breaking** The methods `OtlpTracePipeline::install_simple()` and `OtlpTracePipeline::install_batch()` would now return `TracerProvider` instead of `Tracer`.
163172
These methods would also no longer set the global tracer provider. It would now be the responsibility of users to set it by calling `global::set_tracer_provider(tracer_provider.clone());`. Refer to the [basic-otlp](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp/src/main.rs) and [basic-otlp-http](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs) examples on how to initialize OTLP Trace Exporter.
164173
- **Breaking** Correct the misspelling of "webkpi" to "webpki" in features [#1842](https://github.com/open-telemetry/opentelemetry-rust/pull/1842)
@@ -190,9 +199,10 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
190199
[#1568]: https://github.com/open-telemetry/opentelemetry-rust/pull/1568
191200

192201
### Changed
193-
- **Breaking** Remove global provider for Logs [#1691](https://github.com/open-telemetry/opentelemetry-rust/pull/1691/)
194-
- The method OtlpLogPipeline::install_simple() and OtlpLogPipeline::install_batch() now return `LoggerProvider` instead of
195-
`Logger`. Refer to the [basic-otlp](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp/src/main.rs) and [basic-otlp-http](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs) examples for how to initialize OTLP Log Exporter to use with OpenTelemetryLogBridge and OpenTelemetryTracingBridge respectively.
202+
203+
- **Breaking** Remove global provider for Logs [#1691](https://github.com/open-telemetry/opentelemetry-rust/pull/1691/)
204+
- The method OtlpLogPipeline::install_simple() and OtlpLogPipeline::install_batch() now return `LoggerProvider` instead of
205+
`Logger`. Refer to the [basic-otlp](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp/src/main.rs) and [basic-otlp-http](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs) examples for how to initialize OTLP Log Exporter to use with OpenTelemetryLogBridge and OpenTelemetryTracingBridge respectively.
196206
- Update `opentelemetry` dependency version to 0.23
197207
- Update `opentelemetry_sdk` dependency version to 0.23
198208
- Update `opentelemetry-http` dependency version to 0.12
@@ -202,16 +212,19 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
202212

203213
### Added
204214

205-
- Support custom channels in topic exporters [#1335](https://github.com/open-telemetry/opentelemetry-rust/pull/1335)
215+
- Support custom channels in topic exporters [#1335](https://github.com/open-telemetry/opentelemetry-rust/pull/1335)
206216
- Allow specifying OTLP Tonic metadata from env variable [#1377](https://github.com/open-telemetry/opentelemetry-rust/pull/1377)
207217

208218
### Changed
219+
209220
- Update to tonic 0.11 and prost 0.12 [#1536](https://github.com/open-telemetry/opentelemetry-rust/pull/1536)
210221

211222
### Fixed
223+
212224
- Fix `tonic()` to the use correct port. [#1556](https://github.com/open-telemetry/opentelemetry-rust/pull/1556)
213225

214226
### Removed
227+
215228
- **Breaking** Remove support for surf HTTP client [#1537](https://github.com/open-telemetry/opentelemetry-rust/pull/1537)
216229
- **Breaking** Remove support for grpcio transport [#1534](https://github.com/open-telemetry/opentelemetry-rust/pull/1534)
217230

@@ -268,7 +281,6 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
268281
- Change to export using v0.19.0 protobuf definitions. [#989](https://github.com/open-telemetry/opentelemetry-rust/pull/989).
269282
- Update dependencies and bump MSRV to 1.60 [#969](https://github.com/open-telemetry/opentelemetry-rust/pull/969).
270283

271-
272284
## v0.11.0
273285

274286
### Changed
@@ -321,26 +333,29 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
321333

322334
### Changed
323335

324-
- Allow users to bring their own tonic channel #515
336+
- Allow users to bring their own tonic channel #515
325337
- Remove default surf features #546
326338
- Update to opentelemetry v0.14.0
327339

328340
### v0.6.0
329341

330342
### Added
343+
331344
- Examples on how to connect to an external otlp using tonic, tls and tokio #449
332345
- Examples on how to connect to an external otlp using grpcio and tls #450
333346
- `with_env` method for `OtlpPipelineBuilder` to use environment variables to config otlp pipeline #451
334347
- Update `tracing-grpc` example to include extractors and injectors #464
335348
- Mentioned `service.name` resource in README #476
336349

337350
### Changed
351+
338352
- Update to opentelemetry v0.13.0
339353
- Update `tonic-build` dependency to 0.4 #463
340354
- Update the opentelemetry pipeline to use API to choose grpc layer instead of feature #467
341355
- Rename trace config with_default_sampler to with_sampler #482
342356

343357
### Removed
358+
344359
- Removed `from_env` and use environment variables to initialize the configurations by default #459
345360
- Removed support for running tonic without tokio runtime #483
346361

opentelemetry-otlp/Cargo.toml

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ opentelemetry = { version = "0.29", default-features = false, path = "../opentel
3131
opentelemetry_sdk = { version = "0.29", default-features = false, path = "../opentelemetry-sdk" }
3232
opentelemetry-http = { version = "0.29", path = "../opentelemetry-http", optional = true }
3333
opentelemetry-proto = { version = "0.29", path = "../opentelemetry-proto", default-features = false }
34-
tracing = {workspace = true, optional = true}
34+
tracing = { workspace = true, optional = true }
3535

3636
prost = { workspace = true, optional = true }
3737
tonic = { workspace = true, optional = true }
@@ -46,39 +46,89 @@ serde_json = { workspace = true, optional = true }
4646
[dev-dependencies]
4747
tokio-stream = { workspace = true, features = ["net"] }
4848
# need tokio runtime to run smoke tests.
49-
opentelemetry_sdk = { features = ["trace", "rt-tokio", "testing"], path = "../opentelemetry-sdk" }
49+
opentelemetry_sdk = { features = [
50+
"trace",
51+
"rt-tokio",
52+
"testing",
53+
], path = "../opentelemetry-sdk" }
5054
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
5155
futures-util = { workspace = true }
5256
temp-env = { workspace = true }
5357
tonic = { workspace = true, features = ["router", "server"] }
58+
rcgen = { workspace = true }
59+
tempfile = { workspace = true }
5460

5561
[features]
5662
# telemetry pillars and functions
57-
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/trace"]
58-
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"]
59-
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"]
63+
trace = [
64+
"opentelemetry/trace",
65+
"opentelemetry_sdk/trace",
66+
"opentelemetry-proto/trace",
67+
]
68+
metrics = [
69+
"opentelemetry/metrics",
70+
"opentelemetry_sdk/metrics",
71+
"opentelemetry-proto/metrics",
72+
]
73+
logs = [
74+
"opentelemetry/logs",
75+
"opentelemetry_sdk/logs",
76+
"opentelemetry-proto/logs",
77+
]
6078
internal-logs = ["tracing", "opentelemetry/internal-logs"]
6179

6280
# add ons
6381
serialize = ["serde", "serde_json"]
6482

65-
default = ["http-proto", "reqwest-blocking-client", "trace", "metrics", "logs", "internal-logs"]
83+
default = [
84+
"http-proto",
85+
"reqwest-blocking-client",
86+
"trace",
87+
"metrics",
88+
"logs",
89+
"internal-logs",
90+
]
6691

6792
# grpc using tonic
68-
grpc-tonic = ["tonic", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
93+
grpc-tonic = [
94+
"tonic",
95+
"prost",
96+
"http",
97+
"tokio",
98+
"opentelemetry-proto/gen-tonic",
99+
]
69100
gzip-tonic = ["tonic/gzip"]
70101
zstd-tonic = ["tonic/zstd"]
71102
tls = ["tonic/tls-ring"]
72103
tls-roots = ["tls", "tonic/tls-native-roots"]
73104
tls-webpki-roots = ["tls", "tonic/tls-webpki-roots"]
74105

75106
# http binary
76-
http-proto = ["prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "http", "trace", "metrics"]
77-
http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "opentelemetry-proto/with-serde", "http", "trace", "metrics"]
107+
http-proto = [
108+
"prost",
109+
"opentelemetry-http",
110+
"opentelemetry-proto/gen-tonic-messages",
111+
"http",
112+
"trace",
113+
"metrics",
114+
]
115+
http-json = [
116+
"serde_json",
117+
"prost",
118+
"opentelemetry-http",
119+
"opentelemetry-proto/gen-tonic-messages",
120+
"opentelemetry-proto/with-serde",
121+
"http",
122+
"trace",
123+
"metrics",
124+
]
78125
reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest"]
79126
reqwest-client = ["reqwest", "opentelemetry-http/reqwest"]
80127
reqwest-rustls = ["reqwest", "opentelemetry-http/reqwest-rustls"]
81-
reqwest-rustls-webpki-roots = ["reqwest", "opentelemetry-http/reqwest-rustls-webpki-roots"]
128+
reqwest-rustls-webpki-roots = [
129+
"reqwest",
130+
"opentelemetry-http/reqwest-rustls-webpki-roots",
131+
]
82132
hyper-client = ["opentelemetry-http/hyper"]
83133

84134
# test

0 commit comments

Comments
 (0)