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

Support process.runtime.* resource attributes #2143

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
io.opentelemetry.sdk.extension.resources.OsResource
io.opentelemetry.sdk.extension.resources.ProcessResource
io.opentelemetry.sdk.extension.resources.ProcessRuntimeResource
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public final class ResourceAttributes {
/** The username of the user that owns the process. */
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
* services.
Expand Down