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

sdk-common: add TelemetryResourceDetector #721

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Aug 7, 2024

Reference Link
Spec https://opentelemetry.io/docs/specs/semconv/resource/host/
Java implementation HostResource.java
JavaScript implementation HostDetectorSync.ts

We need TelemetryResourceDetector to build environment-aware TelemetryResource for our Scala SDK.

Some context: #615.

Comment on lines +34 to +37
def detect: F[Option[TelemetryResource]] = Sync[F].delay {
val host = Keys.Host(OS.hostname())
val arch = Keys.Arch(normalizeArch(OS.arch()))

Some(TelemetryResource(Attributes(host, arch), Some(SchemaUrls.Current)))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JS implementation.

Comment on lines +40 to +51
for {
hostOpt <- Sync[F]
.blocking(InetAddress.getLocalHost.getHostName)
.redeem(_ => None, Some(_))

archOpt <- Sync[F].delay(sys.props.get("os.arch"))
} yield {
val host = hostOpt.map(Keys.Host(_))
val arch = archOpt.map(Keys.Arch(_))
val attributes = host.to(Attributes) ++ arch.to(Attributes)
Option.when(attributes.nonEmpty)(
TelemetryResource(attributes, Some(SchemaUrls.Current))
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JVM implementation.

Comment on lines +42 to +49
for {
hostOpt <- Sync[F].delay(detectHost).handleError(_ => None)
archOpt <- Sync[F].delay(sys.props.get("os.arch"))
} yield {
val host = hostOpt.map(Keys.Host(_))
val arch = archOpt.map(Keys.Arch(_))
val attributes = host.to(Attributes) ++ arch.to(Attributes)
Option.when(attributes.nonEmpty)(
TelemetryResource(attributes, Some(SchemaUrls.Current))
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Scala Native implementation.

@iRevive iRevive force-pushed the sdk-common/resource-detector branch 2 times, most recently from 39069a1 to cd57fdc Compare August 7, 2024 17:40
@iRevive iRevive force-pushed the sdk-common/resource-detector branch from cd57fdc to 08bfc85 Compare August 7, 2024 17:51
@iRevive iRevive merged commit 151242b into typelevel:main Aug 10, 2024
10 checks passed
@iRevive iRevive deleted the sdk-common/resource-detector branch August 10, 2024 08:01
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.

1 participant