-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk-common: add
ProcessRuntimeDetector
- Loading branch information
Showing
14 changed files
with
276 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sdk/common/js/src/main/scala/org/typelevel/otel4s/sdk/resource/Process.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.resource | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSImport | ||
|
||
/** A mapping of the Node.js process API. | ||
* | ||
* @see | ||
* [[https://nodejs.org/api/process.html]] | ||
*/ | ||
private object Process { | ||
|
||
@js.native | ||
@JSImport("process", "versions") | ||
def versions: Versions = js.native | ||
|
||
@js.native | ||
trait Versions extends js.Object { | ||
def node: String = js.native | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
.../js/src/main/scala/org/typelevel/otel4s/sdk/resource/ProcessRuntimeDetectorPlatform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.resource | ||
|
||
import cats.effect.Sync | ||
import org.typelevel.otel4s.Attributes | ||
import org.typelevel.otel4s.sdk.TelemetryResource | ||
import org.typelevel.otel4s.semconv.SchemaUrls | ||
|
||
private[resource] trait ProcessRuntimeDetectorPlatform { | ||
self: ProcessRuntimeDetector.type => | ||
|
||
def apply[F[_]: Sync]: TelemetryResourceDetector[F] = | ||
new Detector[F] | ||
|
||
private class Detector[F[_]: Sync] extends TelemetryResourceDetector[F] { | ||
def name: String = Const.Name | ||
|
||
def detect: F[Option[TelemetryResource]] = Sync[F].delay { | ||
val attributes = Attributes( | ||
Keys.Name("nodejs"), | ||
Keys.Version(Process.versions.node), | ||
Keys.Description("Node.js") | ||
) | ||
|
||
Some(TelemetryResource(attributes, Some(SchemaUrls.Current))) | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...jvm/src/main/scala/org/typelevel/otel4s/sdk/resource/ProcessRuntimeDetectorPlatform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.resource | ||
|
||
import cats.effect.Sync | ||
import cats.syntax.apply._ | ||
import cats.syntax.flatMap._ | ||
import cats.syntax.functor._ | ||
import org.typelevel.otel4s.Attributes | ||
import org.typelevel.otel4s.sdk.TelemetryResource | ||
import org.typelevel.otel4s.semconv.SchemaUrls | ||
|
||
private[resource] trait ProcessRuntimeDetectorPlatform { | ||
self: ProcessRuntimeDetector.type => | ||
|
||
def apply[F[_]: Sync]: TelemetryResourceDetector[F] = | ||
new Detector[F] | ||
|
||
private class Detector[F[_]: Sync] extends TelemetryResourceDetector[F] { | ||
def name: String = Const.Name | ||
|
||
def detect: F[Option[TelemetryResource]] = | ||
for { | ||
runtimeName <- Sync[F].delay(sys.props.get("java.runtime.name")) | ||
runtimeVersion <- Sync[F].delay(sys.props.get("java.runtime.version")) | ||
vmVendor <- Sync[F].delay(sys.props.get("java.vm.vendor")) | ||
vmName <- Sync[F].delay(sys.props.get("java.vm.name")) | ||
vmVersion <- Sync[F].delay(sys.props.get("java.vm.version")) | ||
} yield { | ||
val attributes = Attributes.newBuilder | ||
|
||
runtimeName.foreach(name => attributes.addOne(Keys.Name(name))) | ||
runtimeVersion.foreach(name => attributes.addOne(Keys.Version(name))) | ||
(vmVendor, vmName, vmVersion).mapN { (vendor, name, version) => | ||
attributes.addOne(Keys.Description(s"$vendor $name $version")) | ||
} | ||
|
||
Some(TelemetryResource(attributes.result(), Some(SchemaUrls.Current))) | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...ive/src/main/scala/org/typelevel/otel4s/sdk/resource/ProcessRuntimeDetectorPlatform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.resource | ||
|
||
import cats.effect.Sync | ||
import org.typelevel.otel4s.Attributes | ||
import org.typelevel.otel4s.sdk.TelemetryResource | ||
import org.typelevel.otel4s.semconv.SchemaUrls | ||
|
||
private[resource] trait ProcessRuntimeDetectorPlatform { | ||
self: ProcessRuntimeDetector.type => | ||
|
||
def apply[F[_]: Sync]: TelemetryResourceDetector[F] = | ||
new Detector[F] | ||
|
||
private class Detector[F[_]: Sync] extends TelemetryResourceDetector[F] { | ||
def name: String = Const.Name | ||
|
||
def detect: F[Option[TelemetryResource]] = | ||
Sync[F].delay { | ||
val attributes = Attributes( | ||
Keys.Name("scalanative"), | ||
// Keys.Version(""), not available yet | ||
Keys.Description("Scala Native") | ||
) | ||
|
||
Some(TelemetryResource(attributes, Some(SchemaUrls.Current))) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...mmon/shared/src/main/scala/org/typelevel/otel4s/sdk/resource/ProcessRuntimeDetector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s.sdk.resource | ||
|
||
import org.typelevel.otel4s.AttributeKey | ||
|
||
/** Detects runtime details such as name, version, and description. | ||
* | ||
* @see | ||
* https://opentelemetry.io/docs/specs/semconv/resource/process/#process-runtimes | ||
*/ | ||
object ProcessRuntimeDetector extends ProcessRuntimeDetectorPlatform { | ||
|
||
private[sdk] object Const { | ||
val Name = "process_runtime" | ||
} | ||
|
||
private[resource] object Keys { | ||
val Name: AttributeKey[String] = | ||
AttributeKey("process.runtime.name") | ||
|
||
val Version: AttributeKey[String] = | ||
AttributeKey("process.runtime.version") | ||
|
||
val Description: AttributeKey[String] = | ||
AttributeKey("process.runtime.description") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters