Skip to content

feat: configure TLS with environment variables. #2465

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tokio-stream = "0.1"
# required for OpenTelemetry's internal logging macros.
tracing = { version = ">=0.1.40", default-features = false }
# `tracing-core >=0.1.33` is required for compatibility with `tracing >=0.1.40`.
tracing-core = { version = ">=0.1.33", default-features = false }
tracing-core = { version = ">=0.1.33", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
url = { version = "2.5", default-features = false }
anyhow = "1.0.94"
Expand All @@ -71,12 +71,13 @@ percent-encoding = "2.0"
rstest = "0.23.0"
schemars = "0.8"
sysinfo = "0.32"
tempfile = "3.3.0"
testcontainers = "0.23.1"
tracing-log = "0.2"
tracing-opentelemetry = "0.30"
typed-builder = "0.20"
uuid = "1.3"
rcgen = { version = "0.13", features = ["crypto"] }
tempfile = "3.14"

# Aviod use of crates.io version of these crates through the tracing-opentelemetry dependencies
[patch.crates-io]
Expand Down
73 changes: 44 additions & 29 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## vNext

- Update `tonic` dependency version to 0.13
- TLS configuration via environment variables for GRPC exporters.

## 0.29.0

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

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

- **BREAKING**:

- ([#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:
Previous Signature:
```rust
Expand All @@ -84,13 +86,15 @@ Released 2024-Nov-11
MetricsExporterBuilder::default().with_temporality(opentelemetry_sdk::metrics::Temporality::Delta)
```
- ([#2221](https://github.com/open-telemetry/opentelemetry-rust/pull/2221)) **Replaced**:

- The `opentelemetry_otlp::new_pipeline().{trace,logging,metrics}()` interface is now replaced with `{TracerProvider,SdkMeterProvider,LoggerProvider}::builder()`.
- The `opentelemetry_otlp::new_exporter()` interface is now replaced with `{SpanExporter,MetricsExporter,LogExporter}::builder()`.

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

Previous Signature:

```rust
let logger_provider: LoggerProvider = opentelemetry_otlp::new_pipeline()
.logging()
Expand All @@ -102,7 +106,9 @@ Released 2024-Nov-11
)
.install_batch(runtime::Tokio)?;
```

Updated Signature:

```rust
let exporter = LogExporter::builder()
.with_tonic()
Expand All @@ -114,16 +120,19 @@ Released 2024-Nov-11
.with_batch_exporter(exporter, runtime::Tokio)
.build())
```

- **Renamed**

- ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types.
- `MetricsExporter` -> `MetricExporter`
- `MetricsExporterBuilder` -> `MetricExporterBuilder`

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

## v0.26.0

Released 2024-Sep-30

- Update `opentelemetry` dependency version to 0.26
Expand All @@ -141,11 +150,11 @@ Released 2024-Sep-30
- Starting with this version, this crate will align with `opentelemetry` crate
on major,minor versions.
- **Breaking**
The logrecord event-name is added as an attribute only if the feature flag
`populate-logs-event-name` is enabled. The name of the attribute is changed from
"name" to "event.name".
[1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994),
[2050](https://github.com/open-telemetry/opentelemetry-rust/pull/2050)
The logrecord event-name is added as an attribute only if the feature flag
`populate-logs-event-name` is enabled. The name of the attribute is changed from
"name" to "event.name".
[1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994),
[2050](https://github.com/open-telemetry/opentelemetry-rust/pull/2050)

## v0.17.0

Expand All @@ -155,10 +164,10 @@ The logrecord event-name is added as an attribute only if the feature flag
`global::set_meter_provider`. User who setup the pipeline must do it
themselves using `global::set_meter_provider(meter_provider.clone());`.
- Add `with_resource` on `OtlpLogPipeline`, replacing the `with_config` method.
Instead of using
`.with_config(Config::default().with_resource(RESOURCE::default()))` users must
now use `.with_resource(RESOURCE::default())` to configure Resource when using
`OtlpLogPipeline`.
Instead of using
`.with_config(Config::default().with_resource(RESOURCE::default()))` users must
now use `.with_resource(RESOURCE::default())` to configure Resource when using
`OtlpLogPipeline`.
- **Breaking** The methods `OtlpTracePipeline::install_simple()` and `OtlpTracePipeline::install_batch()` would now return `TracerProvider` instead of `Tracer`.
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.
- **Breaking** Correct the misspelling of "webkpi" to "webpki" in features [#1842](https://github.com/open-telemetry/opentelemetry-rust/pull/1842)
Expand Down Expand Up @@ -190,9 +199,10 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
[#1568]: https://github.com/open-telemetry/opentelemetry-rust/pull/1568

### Changed
- **Breaking** Remove global provider for Logs [#1691](https://github.com/open-telemetry/opentelemetry-rust/pull/1691/)
- The method OtlpLogPipeline::install_simple() and OtlpLogPipeline::install_batch() now return `LoggerProvider` instead of
`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.

- **Breaking** Remove global provider for Logs [#1691](https://github.com/open-telemetry/opentelemetry-rust/pull/1691/)
- The method OtlpLogPipeline::install_simple() and OtlpLogPipeline::install_batch() now return `LoggerProvider` instead of
`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.
- Update `opentelemetry` dependency version to 0.23
- Update `opentelemetry_sdk` dependency version to 0.23
- Update `opentelemetry-http` dependency version to 0.12
Expand All @@ -202,16 +212,19 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using

### Added

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

### Changed

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

### Fixed

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

### Removed

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

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


## v0.11.0

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

### Changed

- Allow users to bring their own tonic channel #515
- Allow users to bring their own tonic channel #515
- Remove default surf features #546
- Update to opentelemetry v0.14.0

### v0.6.0

### Added

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

### Changed

- Update to opentelemetry v0.13.0
- Update `tonic-build` dependency to 0.4 #463
- Update the opentelemetry pipeline to use API to choose grpc layer instead of feature #467
- Rename trace config with_default_sampler to with_sampler #482

### Removed

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

Expand Down
70 changes: 60 additions & 10 deletions opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ opentelemetry = { version = "0.29", default-features = false, path = "../opentel
opentelemetry_sdk = { version = "0.29", default-features = false, path = "../opentelemetry-sdk" }
opentelemetry-http = { version = "0.29", path = "../opentelemetry-http", optional = true }
opentelemetry-proto = { version = "0.29", path = "../opentelemetry-proto", default-features = false }
tracing = {workspace = true, optional = true}
tracing = { workspace = true, optional = true }

prost = { workspace = true, optional = true }
tonic = { workspace = true, optional = true }
Expand All @@ -46,39 +46,89 @@ serde_json = { workspace = true, optional = true }
[dev-dependencies]
tokio-stream = { workspace = true, features = ["net"] }
# need tokio runtime to run smoke tests.
opentelemetry_sdk = { features = ["trace", "rt-tokio", "testing"], path = "../opentelemetry-sdk" }
opentelemetry_sdk = { features = [
"trace",
"rt-tokio",
"testing",
], path = "../opentelemetry-sdk" }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
futures-util = { workspace = true }
temp-env = { workspace = true }
tonic = { workspace = true, features = ["router", "server"] }
rcgen = { workspace = true }
tempfile = { workspace = true }

[features]
# telemetry pillars and functions
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/trace"]
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"]
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"]
trace = [
"opentelemetry/trace",
"opentelemetry_sdk/trace",
"opentelemetry-proto/trace",
]
metrics = [
"opentelemetry/metrics",
"opentelemetry_sdk/metrics",
"opentelemetry-proto/metrics",
]
logs = [
"opentelemetry/logs",
"opentelemetry_sdk/logs",
"opentelemetry-proto/logs",
]
internal-logs = ["tracing", "opentelemetry/internal-logs"]

# add ons
serialize = ["serde", "serde_json"]

default = ["http-proto", "reqwest-blocking-client", "trace", "metrics", "logs", "internal-logs"]
default = [
"http-proto",
"reqwest-blocking-client",
"trace",
"metrics",
"logs",
"internal-logs",
]

# grpc using tonic
grpc-tonic = ["tonic", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
grpc-tonic = [
"tonic",
"prost",
"http",
"tokio",
"opentelemetry-proto/gen-tonic",
]
gzip-tonic = ["tonic/gzip"]
zstd-tonic = ["tonic/zstd"]
tls = ["tonic/tls-ring"]
tls-roots = ["tls", "tonic/tls-native-roots"]
tls-webpki-roots = ["tls", "tonic/tls-webpki-roots"]

# http binary
http-proto = ["prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "http", "trace", "metrics"]
http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "opentelemetry-proto/with-serde", "http", "trace", "metrics"]
http-proto = [
"prost",
"opentelemetry-http",
"opentelemetry-proto/gen-tonic-messages",
"http",
"trace",
"metrics",
]
http-json = [
"serde_json",
"prost",
"opentelemetry-http",
"opentelemetry-proto/gen-tonic-messages",
"opentelemetry-proto/with-serde",
"http",
"trace",
"metrics",
]
reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest"]
reqwest-client = ["reqwest", "opentelemetry-http/reqwest"]
reqwest-rustls = ["reqwest", "opentelemetry-http/reqwest-rustls"]
reqwest-rustls-webpki-roots = ["reqwest", "opentelemetry-http/reqwest-rustls-webpki-roots"]
reqwest-rustls-webpki-roots = [
"reqwest",
"opentelemetry-http/reqwest-rustls-webpki-roots",
]
hyper-client = ["opentelemetry-http/hyper"]

# test
Expand Down
Loading
Loading