Support process.runtime.* resource attributes (#2143)
* Support process.runtime.* resource attributes * Code review comments * Add process.runtime.* attributes to README.md
This commit is contained in:
parent
ee0dac1a97
commit
2130644667
|
|
@ -19,13 +19,24 @@ Implemented attributes:
|
||||||
|
|
||||||
Implementation: `io.opentelemetry.sdk.extension.resources.ProcessResource`
|
Implementation: `io.opentelemetry.sdk.extension.resources.ProcessResource`
|
||||||
|
|
||||||
Specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/semantic_conventions/process.md
|
Specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/semantic_conventions/process.md#process
|
||||||
|
|
||||||
Implemented attributes:
|
Implemented attributes:
|
||||||
- `process.pid`
|
- `process.pid`
|
||||||
- `process.executable.path` (note, we assume the `java` binary is located in the `bin` subfolder of `JAVA_HOME`)
|
- `process.executable.path` (note, we assume the `java` binary is located in the `bin` subfolder of `JAVA_HOME`)
|
||||||
- `process.command_line` (note this includes all system properties and arguments when running)
|
- `process.command_line` (note this includes all system properties and arguments when running)
|
||||||
|
|
||||||
|
### Java Runtime
|
||||||
|
|
||||||
|
Implementation: `io.opentelemetry.sdk.extension.resources.ProcessRuntimeResource`
|
||||||
|
|
||||||
|
Specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/semantic_conventions/process.md#process-runtimes
|
||||||
|
|
||||||
|
Implemented attributes:
|
||||||
|
- `process.runtime.name`
|
||||||
|
- `process.runtime.version`
|
||||||
|
- `process.runtime.description`
|
||||||
|
|
||||||
## Platforms
|
## Platforms
|
||||||
|
|
||||||
This package currently does not run on Android. It has been verified on OpenJDK and should work on
|
This package currently does not run on Android. It has been verified on OpenJDK and should work on
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.extension.resources;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.resources.ResourceAttributes.PROCESS_RUNTIME_DESCRIPTION;
|
||||||
|
import static io.opentelemetry.sdk.resources.ResourceAttributes.PROCESS_RUNTIME_NAME;
|
||||||
|
import static io.opentelemetry.sdk.resources.ResourceAttributes.PROCESS_RUNTIME_VERSION;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.sdk.resources.ResourceProvider;
|
||||||
|
|
||||||
|
/** {@link ResourceProvider} which provides information about the Java runtime. */
|
||||||
|
public final class ProcessRuntimeResource extends ResourceProvider {
|
||||||
|
@Override
|
||||||
|
protected Attributes getAttributes() {
|
||||||
|
try {
|
||||||
|
String name = System.getProperty("java.runtime.name");
|
||||||
|
String version = System.getProperty("java.runtime.version");
|
||||||
|
String description =
|
||||||
|
System.getProperty("java.vm.vendor")
|
||||||
|
+ " "
|
||||||
|
+ System.getProperty("java.vm.name")
|
||||||
|
+ " "
|
||||||
|
+ System.getProperty("java.vm.version");
|
||||||
|
|
||||||
|
return Attributes.of(
|
||||||
|
PROCESS_RUNTIME_NAME,
|
||||||
|
name,
|
||||||
|
PROCESS_RUNTIME_VERSION,
|
||||||
|
version,
|
||||||
|
PROCESS_RUNTIME_DESCRIPTION,
|
||||||
|
description);
|
||||||
|
} catch (SecurityException ignored) {
|
||||||
|
return Attributes.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
io.opentelemetry.sdk.extension.resources.OsResource
|
io.opentelemetry.sdk.extension.resources.OsResource
|
||||||
io.opentelemetry.sdk.extension.resources.ProcessResource
|
io.opentelemetry.sdk.extension.resources.ProcessResource
|
||||||
|
io.opentelemetry.sdk.extension.resources.ProcessRuntimeResource
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.sdk.extension.resources;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.ReadableAttributes;
|
||||||
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
|
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class ProcessRuntimeResourceTest {
|
||||||
|
@Test
|
||||||
|
void shouldCreateRuntimeAttributes() {
|
||||||
|
// when
|
||||||
|
ReadableAttributes attributes = new ProcessRuntimeResource().getAttributes();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotBlank();
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_VERSION)).isNotBlank();
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_DESCRIPTION)).isNotBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void inDefault() {
|
||||||
|
// when
|
||||||
|
ReadableAttributes attributes = Resource.getDefault().getAttributes();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotBlank();
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_VERSION)).isNotBlank();
|
||||||
|
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_DESCRIPTION)).isNotBlank();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,6 +51,24 @@ public final class ResourceAttributes {
|
||||||
/** The username of the user that owns the process. */
|
/** The username of the user that owns the process. */
|
||||||
public static final AttributeKey<String> PROCESS_OWNER = stringKey("process.owner");
|
public static final AttributeKey<String> PROCESS_OWNER = stringKey("process.owner");
|
||||||
|
|
||||||
|
// TODO: these should be removed once SemanticAttributes contain process.runtime.*
|
||||||
|
/**
|
||||||
|
* The name of the runtime of this process. For compiled native binaries, this SHOULD be the name
|
||||||
|
* of the compiler.
|
||||||
|
*/
|
||||||
|
public static final AttributeKey<String> PROCESS_RUNTIME_NAME = stringKey("process.runtime.name");
|
||||||
|
/**
|
||||||
|
* The version of the runtime of this process, as returned by the runtime without modification.
|
||||||
|
*/
|
||||||
|
public static final AttributeKey<String> PROCESS_RUNTIME_VERSION =
|
||||||
|
stringKey("process.runtime.version");
|
||||||
|
/**
|
||||||
|
* An additional description about the runtime of the process, for example a specific vendor
|
||||||
|
* customization of the runtime environment.
|
||||||
|
*/
|
||||||
|
public static final AttributeKey<String> PROCESS_RUNTIME_DESCRIPTION =
|
||||||
|
stringKey("process.runtime.description");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logical name of the service. MUST be the same for all instances of horizontally scaled
|
* Logical name of the service. MUST be the same for all instances of horizontally scaled
|
||||||
* services.
|
* services.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue