Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: configure TLS with environment variables. #2465

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jvanz
Copy link

@jvanz jvanz commented Dec 23, 2024

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).

Partially fixes #774

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@jvanz jvanz force-pushed the tls-envvars branch 3 times, most recently from 50894e9 to 5031002 Compare December 24, 2024 16:12
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

Attention: Patch coverage is 5.36913% with 141 lines in your changes missing coverage. Please review.

Project coverage is 77.4%. Comparing base (68af3bb) to head (07e62dd).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-otlp/src/exporter/tonic/mod.rs 0.0% 121 Missing ⚠️
opentelemetry-otlp/src/exporter/mod.rs 28.5% 20 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2465     +/-   ##
=======================================
- Coverage   77.9%   77.4%   -0.5%     
=======================================
  Files        123     123             
  Lines      22944   23168    +224     
=======================================
+ Hits       17880   17948     +68     
- Misses      5064    5220    +156     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jvanz jvanz force-pushed the tls-envvars branch 3 times, most recently from 9458a03 to 093a1ce Compare December 31, 2024 14:46
@jvanz jvanz marked this pull request as ready for review December 31, 2024 14:50
@jvanz jvanz requested a review from a team as a code owner December 31, 2024 14:50
@jvanz
Copy link
Author

jvanz commented Jan 20, 2025

@TommyCpp , how can we move this forward? 😄

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 <[email protected]>
@TommyCpp
Copy link
Contributor

👀 Will take a look today

@TommyCpp TommyCpp self-assigned this Jan 20, 2025
opentelemetry-otlp/CHANGELOG.md Outdated Show resolved Hide resolved
opentelemetry-otlp/src/exporter/mod.rs Show resolved Hide resolved
@TommyCpp TommyCpp removed their assignment Jan 21, 2025
jvanz added 2 commits January 22, 2025 17:05
Fix typo in the changelog.

Signed-off-by: José Guilherme Vanz <[email protected]>
Add missing TLS configuration directives.

Signed-off-by: José Guilherme Vanz <[email protected]>
@jvanz jvanz requested a review from TommyCpp January 22, 2025 20:10
Add comments formatting adding missing periods at the end.

Signed-off-by: José Guilherme Vanz <[email protected]>
@jvanz jvanz requested a review from ThomsonTan January 27, 2025 18:11
@@ -136,3 +151,150 @@ async fn smoke_tracer() {
let first_event = first_span.events.first().unwrap();
assert_eq!("my-test-event", first_event.name);
}

#[tokio::test(flavor = "multi_thread")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now have automated integration tests. Could these tests be added there? It does not have anything validating the TLS code paths..
https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/tests/integration_test/tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1., this needs to be moved to integrations tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
let insecure = config.insecure.unwrap_or_else(|| {
env::var(signal_insecure_var)
.or_else(|_| env::var(OTEL_EXPORTER_OTLP_INSECURE))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't done a full look, but wondering what is the priority order when signal specific ENV variables and this is present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code (specifically resolve_tls_config), the priority order seems to be:
ClientTlsConfig -> signal_specific_env -> otlp_generic_env

But need @jvanz to confirm :)

@cijothomas cijothomas requested a review from lalitb January 27, 2025 21:07
@@ -27,6 +27,18 @@ pub const OTEL_EXPORTER_OTLP_HEADERS: &str = "OTEL_EXPORTER_OTLP_HEADERS";
pub const OTEL_EXPORTER_OTLP_PROTOCOL: &str = "OTEL_EXPORTER_OTLP_PROTOCOL";
/// Compression algorithm to use, defaults to none.
pub const OTEL_EXPORTER_OTLP_COMPRESSION: &str = "OTEL_EXPORTER_OTLP_COMPRESSION";
/// Certificate file to validate the OTLP server connection.
#[cfg(feature = "tls")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tls feature flag is specific to grpc-tonic. Just to be clear -this PR is only adding TLS support for grpc, and not http?

@@ -217,6 +268,34 @@ impl<B: HasExportConfig> WithExportConfig for B {
self.export_config().endpoint = exporter_config.endpoint;
self.export_config().protocol = exporter_config.protocol;
self.export_config().timeout = exporter_config.timeout;
#[cfg(feature = "tls")]
{
self.export_config().insecure = Some(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.map_err(crate::Error::from)?,
None => endpoint,
{
let insecure = config.insecure.unwrap_or_else(|| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me - there would always be a default value associated with the insecure, which means else part will never execute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support all configuration of otlp exporter
5 participants