Skip to content

Commit d56a40a

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 825ef3a commit d56a40a

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
@@ -41,23 +41,23 @@ impl OtelConfig {
4141
self.logs_endpoint.clone().unwrap_or_else(|| {
4242
self.observability_endpoint
4343
.clone()
44-
.unwrap_or_else(|| self.default_endpoint().to_string())
44+
.unwrap_or_else(|| self.default_endpoint(OtelSignal::Logs))
4545
})
4646
}
4747

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

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

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

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

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

0 commit comments

Comments
 (0)