Skip to content

Commit

Permalink
sdk: use TelemetryResource.default as an initial resource in `Telem…
Browse files Browse the repository at this point in the history
…etryResourceAutoConfigure`
  • Loading branch information
iRevive committed Mar 4, 2024
1 parent c6ad789 commit 6eeb457
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OpenTelemetrySdkSuite extends CatsEffectSuite {

private val DefaultSdk =
sdkToString(
TelemetryResource.empty,
TelemetryResource.default,
Sampler.parentBased(Sampler.AlwaysOn)
)

Expand All @@ -56,7 +56,7 @@ class OpenTelemetrySdkSuite extends CatsEffectSuite {
"OpenTelemetrySdk{" +
"meterProvider=MeterProvider.Noop, " +
"tracerProvider=TracerProvider.Noop, " +
s"propagators=ContextPropagators.Noop}, resource=${TelemetryResource.empty}}"
s"propagators=ContextPropagators.Noop}, resource=${TelemetryResource.default}}"

test("withConfig - use the given config") {
val config = Config.ofProps(Map("otel.traces.exporter" -> "none"))
Expand Down Expand Up @@ -261,7 +261,7 @@ class OpenTelemetrySdkSuite extends CatsEffectSuite {
}

private def sdkToString(
resource: TelemetryResource = TelemetryResource.empty,
resource: TelemetryResource = TelemetryResource.default,
sampler: Sampler = Sampler.parentBased(Sampler.AlwaysOn),
propagators: ContextPropagators[Context] = ContextPropagators.of(
W3CTraceContextPropagator.default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ private final class TelemetryResourceAutoConfigure[F[_]: MonadThrow]
.flatten
.map(value => ResourceAttributes.ServiceName(value))

TelemetryResource(
val default = TelemetryResource.default
val fromEnv = TelemetryResource(
Attributes.fromSpecific(attributes ++ serviceName.toSeq)
)

default.mergeUnsafe(fromEnv)
}

Resource.eval(MonadThrow[F].fromEither(attempt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import munit.CatsEffectSuite

class TelemetryResourceAutoConfigureSuite extends CatsEffectSuite {

test("load from an empty config") {
test("load from an empty config - use default as a fallback") {
val config = Config(Map.empty, Map.empty, Map.empty)
TelemetryResourceAutoConfigure[IO].configure(config).use { resource =>
IO(assertEquals(resource, TelemetryResource.empty))
IO(assertEquals(resource, TelemetryResource.default))
}
}

test("load from the config") {
test("load from the config - use default as an initial resource") {
val props = Map(
"otel.service.name" -> "some-service",
"otel.resource.attributes" -> "key1=val1,key2=val2,key3=val3",
Expand All @@ -44,8 +44,12 @@ class TelemetryResourceAutoConfigureSuite extends CatsEffectSuite {
Attribute("service.name", "some-service")
)

val expected = TelemetryResource.default.mergeUnsafe(
TelemetryResource(expectedAttributes)
)

TelemetryResourceAutoConfigure[IO].configure(config).use { resource =>
IO(assertEquals(resource, TelemetryResource(expectedAttributes)))
IO(assertEquals(resource, expected))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SdkTracesSuite extends CatsEffectSuite {

private val DefaultTraces =
tracesToString(
TelemetryResource.empty,
TelemetryResource.default,
Sampler.parentBased(Sampler.AlwaysOn)
)

Expand Down Expand Up @@ -258,7 +258,7 @@ class SdkTracesSuite extends CatsEffectSuite {
}

private def tracesToString(
resource: TelemetryResource = TelemetryResource.empty,
resource: TelemetryResource = TelemetryResource.default,
sampler: Sampler = Sampler.parentBased(Sampler.AlwaysOn),
propagators: ContextPropagators[Context] = ContextPropagators.of(
W3CTraceContextPropagator.default,
Expand Down

0 comments on commit 6eeb457

Please sign in to comment.