Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
* refactor(sdk-metrics): simplify AllowList and DenyList processors [#6159](https://github.com/open-telemetry/opentelemetry-js/pull/6159) @cjihrig
* chore: disallow constructor parameter property syntax [#6187](https://github.com/open-telemetry/opentelemetry-js/pull/6187) @legendecas
* refactor(sdk-metrics): use test() instead of match() in isValidName() [#6205](https://github.com/open-telemetry/opentelemetry-js/pull/6205) @cjihrig
* refactor(core,resources): consolidate platform-specific code [#6208](https://github.com/open-telemetry/opentelemetry-js/pull/6208) @overbalance

## 2.2.0

Expand Down
7 changes: 5 additions & 2 deletions packages/opentelemetry-core/src/platform/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export {
getNumberFromEnv,
getStringListFromEnv,
} from './environment';
export { _globalThis } from './globalThis';
export { otperformance } from './performance';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';

// Use global performance which is available in both Node.js (18+) and browsers
export const otperformance: { now(): number; readonly timeOrigin: number } =
performance;
18 changes: 0 additions & 18 deletions packages/opentelemetry-core/src/platform/browser/performance.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/opentelemetry-core/src/platform/node/globalThis.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/opentelemetry-core/src/platform/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export {
getNumberFromEnv,
getStringListFromEnv,
} from './environment';
export { _globalThis } from './globalThis';
export { otperformance } from './performance';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';

// Use global performance which is available in both Node.js (18+) and browsers
export const otperformance: { now(): number; readonly timeOrigin: number } =
performance;
20 changes: 0 additions & 20 deletions packages/opentelemetry-core/src/platform/node/performance.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/opentelemetry-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js",
"./src/detectors/platform/index.ts": "./src/detectors/platform/browser/index.ts",
"./build/esm/detectors/platform/index.js": "./build/esm/detectors/platform/browser/index.js",
"./build/esnext/detectors/platform/index.js": "./build/esnext/detectors/platform/browser/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-resources/src/ResourceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ATTR_TELEMETRY_SDK_VERSION,
} from '@opentelemetry/semantic-conventions';
import { Resource } from './Resource';
import { defaultServiceName } from './platform';
import { defaultServiceName } from './default-service-name';
import {
DetectedResource,
DetectedResourceAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
* limitations under the License.
*/

// Check if we are in a Node.js environment and if so, use the process.argv0 property
// to determine the default service name
const DEFAULT_SERVICE_NAME =
typeof process === 'object' &&
typeof process.argv0 === 'string' &&
process.argv0.length > 0
? `unknown_service:${process.argv0}`
: 'unknown_service';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@overbalance
This breaks on vercel edge environments

@andreiborza andreiborza Jan 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @overbalance, as @chargome mentioned, this unfortunately breaks our vercel-edge environment due to process.argv0 being a node api.

We ended up having to bundle in @opentelemetry/resources and any code that uses it. It's not ideal.

Any way we can figure out a workaround here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chargome @andreiborza check out this other PR I've had out for review. Do you think it would solve your issue: #6257

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

hey, that might work! Thanks for tackling this 🙏

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@andreiborza You said this "breaks"? What is the break? Inferring from @overbalance's PR there is warning from vercel-edge static analysis of some sort? Can you show an example?

For example, I don't recall here about warnings/breakages from this old change that was feature-testing for Node.js' process object: https://github.com/open-telemetry/opentelemetry-js/pull/4604/files#diff-7775cbc8f9eed30ff77488613bcbabec57446d86f655166fbdb5f7db4579a0b6R29

In that case it was checking global.process?.<something>.
If the code here in this PR used global.process instead of process, would that make the static analysis warnings go away?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here's an example run of a nextjs app using our vercel-edge SDK: https://github.com/getsentry/sentry-javascript/actions/runs/20844816035/job/59886209607?pr=18734#step:16:157

We end up getting

 'A Node.js API is used (process.argv0 at line: 19) which is not supported in the Edge Runtime.\n' +

issues when building the app.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @andreiborza I was able to replicate and solve the issue: #6257


export function defaultServiceName(): string {
return `unknown_service:${process.argv0}`;
return DEFAULT_SERVICE_NAME;
}
2 changes: 1 addition & 1 deletion packages/opentelemetry-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
defaultResource,
emptyResource,
} from './ResourceImpl';
export { defaultServiceName } from './platform';
export { defaultServiceName } from './default-service-name';
export type {
ResourceDetector,
DetectedResource,
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions packages/opentelemetry-resources/src/platform/browser/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/opentelemetry-resources/src/platform/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/opentelemetry-resources/src/platform/node/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/

import * as assert from 'assert';
import { defaultServiceName } from '../src/default-service-name';

const isNode = typeof process === 'object' && typeof process.argv0 === 'string';

describe('defaultServiceName', () => {
it('returns unknown_service prefix', () => {
const serviceName = defaultServiceName();
assert.ok(serviceName.startsWith('unknown_service'));
});

if (isNode) {
it('includes process.argv0 in Node.js', () => {
const serviceName = defaultServiceName();
assert.ok(serviceName.startsWith('unknown_service:'));
assert.ok(serviceName.length > 'unknown_service:'.length);
});
} else {
it('returns plain unknown_service in browser', () => {
const serviceName = defaultServiceName();
assert.strictEqual(serviceName, 'unknown_service');
});
}

it('returns consistent value on multiple calls', () => {
const serviceName1 = defaultServiceName();
const serviceName2 = defaultServiceName();
assert.strictEqual(serviceName1, serviceName2);
});
});