8000 feat(opentelemetry-resources): add schema url by c-ehrlich · Pull Request #5753 · open-telemetry/opentelemetry-js · GitHub
[go: up one dir, main page]

Skip to content

Conversation

c-ehrlich
Copy link
Contributor
@c-ehrlich c-ehrlich commented Jun 12, 2025

Which problem is this PR solving?

Resolves #4182

Short description of the changes

The JavaScript SDK, unlike most others, currently does not give the ability to provide a Schema URL to a resource. See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-creation

This PR implements the ability to provide it.

There was a previous attempt at this by another contributor, which was closed: #5070

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

npm run test

  • should create resource with schema URL
  • should create resource without schema URL
  • should merge resources with schema URL priority given to other resource
  • should retain schema URL from base resource when other has no schema URL
  • should retain schema URL from the resource that has it when merging
  • should have empty schema URL when merging resources with no schema URL
  • should handle merging with empty string schema URLs
  • should maintain backward compatibility - getSchemaUrl is optional
  • should work with async attributes and schema URLs

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@c-ehrlich c-ehrlich marked this pull request as ready for review June 12, 2025 14:22
@c-ehrlich c-ehrlich requested a review from a team as a code owner June 12, 2025 14:22
Copy link
Member
@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

thank you for working on this 🙂

@c-ehrlich c-ehrlich requested a review from pichlermarc June 16, 2025 06:17
Copy link
codecov bot commented Jun 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.05%. Comparing base (dccb9c4) to head (fefb405).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5753      +/-   ##
==========================================
+ Coverage   95.03%   95.05%   +0.01%     
==========================================
  Files         306      306              
  Lines        7969     8001      +32     
  Branches     1611     1620       +9     
==========================================
+ Hits         7573     7605      +32     
  Misses        396      396              
Files with missing lines Coverage Δ
...l/packages/otlp-transformer/src/common/internal.ts 100.00% <100.00%> (ø)
...tal/packages/otlp-transformer/src/logs/internal.ts 100.00% <100.00%> (ø)
.../packages/otlp-transformer/src/metrics/internal.ts 100.00% <100.00%> (ø)
...al/packages/otlp-transformer/src/trace/internal.ts 98.43% <100.00%> (+0.02%) ⬆️
...ckages/opentelemetry-resources/src/ResourceImpl.ts 98.90% <100.00%> (+0.41%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member
@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

thanks for addressing the comments, overall this looks good already - just one small blocker left 🙂

@dyladan dyladan requested a review from pichlermarc July 16, 2025 16:49
@dyladan
Copy link
Member
dyladan commented Jul 16, 2025

Looks like most things are resolved here. After another round of reviews I think this can merge.

Copy link
Member
@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

LGTM

@dyladan dyladan dismissed pichlermarc’s stale review July 22, 2025 19:52

Changes addressed

Comment on lines 201 to 225
if (schemaUrl === undefined || schemaUrl === '') {
return schemaUrl;
}

// Reject any ASCII C0 control (0x00–0x1F), SPACE (0x20) or DEL (0x7F)
// This ensures consistent behavior across Node.js and browser environments
// eslint-disable-next-line no-control-regex
if (/[\x00-\x20\x7F]/.test(schemaUrl)) {
diag.warn(INVALID_SCHEMA_URL_MESSAGE, schemaUrl);
return undefined;
}

try {
const url = new URL(schemaUrl);

if (url.protocol !== 'http:' && url.protocol !== 'https:') {
diag.warn(INVALID_SCHEMA_URL_MESSAGE, schemaUrl);
return undefined;
}

return schemaUrl;
} catch {
diag.warn(INVALID_SCHEMA_URL_MESSAGE, schemaUrl);
return undefined;
}
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, do other SDK validate the schema URL?
I'm wondering if we'd be overly strict here.

Copy link
Contributor Author
@c-ehrlich c-ehrlich Aug 15, 2025

Choose a reason for hiding this comment

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

Was added as a response to this #5753 (comment)

What would you suggest? Maybe just a runtime type guard to ensure it's either a string or undefined, and fall back to undefined if not?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just a runtime type guard to ensure it's either a string or undefined, and fall back to undefined if not?

Yes I think that works for me. In Java they don't validate the schemaUrl, they also don't do it in Python - looking at the spec there's no statement about having to validate schema URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes, let me know what you think :)

Copy link
Member
@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

looks good, thanks! 🙂

@pichlermarc pichlermarc enabled auto-merge August 20, 2025 16:54
@pichlermarc pichlermarc added this pull request to the merge queue Aug 20, 2025
Merged via the queue into open-telemetry:main with commit 23677fd Aug 20, 2025
24 checks passed
@opentelemetrybot
Copy link
Contributor

Thank you for your contribution @c-ehrlich! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Joozty pushed a commit to Joozty/opentelemetry-js that referenced this pull request Sep 9, 2025
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
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.

Add Schema URL for resources
5 participants
0