Repository navigation
Update the default resource to include telemetry.sdk entity #8927
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.sdk.common.internal.OtelVersion; | ||
| import io.opentelemetry.sdk.common.internal.SemConvConstants; | ||
| import io.opentelemetry.sdk.resources.internal.AttributeCheckUtil; | ||
| import io.opentelemetry.sdk.resources.internal.Entity; | ||
| import io.opentelemetry.sdk.resources.internal.EntityUtil; | ||
|
|
@@ -32,38 +33,40 @@ | |
| public abstract class Resource { | ||
| private static final Logger logger = Logger.getLogger(Resource.class.getName()); | ||
|
|
||
| private static final AttributeKey<String> SERVICE_NAME = AttributeKey.stringKey("service.name"); | ||
| private static final AttributeKey<String> TELEMETRY_SDK_LANGUAGE = | ||
| AttributeKey.stringKey("telemetry.sdk.language"); | ||
| private static final AttributeKey<String> TELEMETRY_SDK_NAME = | ||
| AttributeKey.stringKey("telemetry.sdk.name"); | ||
| private static final AttributeKey<String> TELEMETRY_SDK_VERSION = | ||
| AttributeKey.stringKey("telemetry.sdk.version"); | ||
| private static final Resource EMPTY = create(Attributes.empty()); | ||
| private static final Resource TELEMETRY_SDK; | ||
|
|
||
| /** | ||
| * The MANDATORY Resource instance contains the mandatory attributes that must be used if they are | ||
| * not provided by the Resource that is given to an SDK signal provider. | ||
| */ | ||
| private static final Resource MANDATORY = | ||
| create(Attributes.of(SERVICE_NAME, "unknown_service:java")); | ||
| create(Attributes.of(SemConvConstants.SERVICE_NAME, "unknown_service:java")); | ||
|
|
||
| static { | ||
| TELEMETRY_SDK = | ||
| create( | ||
| Attributes.builder() | ||
| .put(TELEMETRY_SDK_NAME, "opentelemetry") | ||
| .put(TELEMETRY_SDK_LANGUAGE, "java") | ||
| .put(TELEMETRY_SDK_VERSION, OtelVersion.VERSION) | ||
| .build()); | ||
| } | ||
| private static final Resource TELEMETRY_SDK = | ||
|
jack-berg marked this conversation as resolved.
Resolved
|
||
| builder() | ||
| .addEntity( | ||
| Entity.builder( | ||
| SemConvConstants.TELEMETRY_SDK_TYPE, | ||
| Attributes.of( | ||
| SemConvConstants.TELEMETRY_SDK_NAME, | ||
| "opentelemetry", | ||
| SemConvConstants.TELEMETRY_SDK_LANGUAGE, | ||
| "java")) | ||
| .setDescription( | ||
| Attributes.of(SemConvConstants.TELEMETRY_SDK_VERSION, OtelVersion.VERSION)) | ||
| .setSchemaUrl(SemConvConstants.SCHEMA_URL_V1_40_0) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| private static final Resource DEFAULT = MANDATORY.merge(TELEMETRY_SDK); | ||
| // TODO(jack-berg): Explicitly null out schema url to avoid avoid assigning schemaUrl to default | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude: possible problem: Schema URL nulling on DEFAULT The nulling works on DEFAULT itself. The attributes and the telemetry.sdk entity stay intact, the resource schemaUrl is null, and the entity keeps 1.40.0. Resource.merge() also behaves as before, because it uses buildWithSchemaUrl and a null base takes the other side's URL. The nulling does not survive toBuilder().build(): ResourceBuilder derives 1.40.0 from the single entity. So the common Resource.getDefault().toBuilder()...build() pattern now yields a resource with schemaUrl 1.40.0, which was null before. If that resource is later merged with a resource that has a different schemaUrl, the result is null and an info log is written. The PR's own test asserts this behavior. The TODO says the goal is to avoid assigning a schemaUrl, so the reviewer should decide whether this is acceptable or whether toBuilder() should pin a null URL. Evidence:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the request to preserve a null resource schema URL through
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more of a "is this intended or not" question, rather than a suggestion of a fix.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the special nulling. It didn't survive rebuilding and made schema handling depend on the construction path. We already associate a schema url elsewhere we construct entity aware resources (e.g. |
||
| // resource which previously had none. Revisit when entities stabilize. | ||
| private static final Resource DEFAULT = | ||
| builder().putAll(MANDATORY).putAll(TELEMETRY_SDK).buildWithSchemaUrl(null); | ||
|
|
||
| /** | ||
| * Returns the default {@link Resource}. This resource contains the default attributes provided by | ||
| * the SDK. | ||
| * the SDK, with the telemetry SDK attributes associated with an experimental {@code | ||
| * telemetry.sdk} entity. | ||
| * | ||
| * @return a {@code Resource}. | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.