Skip to content

Commit 45ce31c

Browse files
committed
fix: Add signal-specific path components to OtelConfig's default endpoints
Fixes wasmCloud#2265 Signed-off-by: Joonas Bergius <joonas@cosmonic.com>
1 parent 1f204ba commit 45ce31c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

crates/core/src/otel.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ impl OtelConfig {
4040
self.logs_endpoint.clone().unwrap_or_else(|| {
4141
self.observability_endpoint
4242
.clone()
43-
.unwrap_or_else(|| self.default_endpoint().to_string())
43+
.unwrap_or_else(|| self.default_endpoint(OtelSignal::Logs))
4444
})
4545
}
4646

4747
pub fn metrics_endpoint(&self) -> String {
4848
self.metrics_endpoint.clone().unwrap_or_else(|| {
4949
self.observability_endpoint
5050
.clone()
51-
.unwrap_or_else(|| self.default_endpoint().to_string())
51+
.unwrap_or_else(|| self.default_endpoint(OtelSignal::Metrics))
5252
})
5353
}
5454

5555
pub fn traces_endpoint(&self) -> String {
5656
self.traces_endpoint.clone().unwrap_or_else(|| {
5757
self.observability_endpoint
5858
.clone()
59-
.unwrap_or_else(|| self.default_endpoint().to_string())
59+
.unwrap_or_else(|| self.default_endpoint(OtelSignal::Traces))
6060
})
6161
}
6262

@@ -72,10 +72,20 @@ impl OtelConfig {
7272
self.enable_traces.unwrap_or(self.enable_observability)
7373
}
7474

75-
fn default_endpoint(&self) -> &str {
75+
fn default_endpoint(&self, signal: OtelSignal) -> String {
7676
match self.protocol {
77-
OtelProtocol::Grpc => OTEL_EXPORTER_OTLP_GRPC_ENDPOINT_DEFAULT,
78-
OtelProtocol::Http => OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT,
77+
// gRPC endpoint does not include any signal specific path components.
78+
OtelProtocol::Grpc => OTEL_EXPORTER_OTLP_GRPC_ENDPOINT_DEFAULT.to_string(),
79+
// http endpoint includes a signal-specific path component.
80+
OtelProtocol::Http => match signal {
81+
OtelSignal::Traces => {
82+
format!("{}/v1/traces", OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT)
83+
}
84+
OtelSignal::Metrics => {
85+
format!("{}/v1/metrics", OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT)
86+
}
87+
OtelSignal::Logs => format!("{}/v1/logs", OTEL_EXPORTER_OTLP_HTTP_ENDPOINT_DEFAULT),
88+
},
7989
}
8090
}
8191
}
@@ -86,6 +96,13 @@ pub enum OtelProtocol {
8696
Http,
8797
}
8898

99+
// Represents https://opentelemetry.io/docs/concepts/signals/
100+
enum OtelSignal {
101+
Traces,
102+
Metrics,
103+
Logs,
104+
}
105+
89106
impl Default for OtelProtocol {
90107
fn default() -> Self {
91108
Self::Http

0 commit comments

Comments
 (0)