File tree Expand file tree Collapse file tree
packages/opentelemetry-resources/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17- // Check if we are in a Node.js environment and if so, use the process.argv0 property
18- // to determine the default service name
19- const DEFAULT_SERVICE_NAME =
20- typeof process === 'object' &&
21- typeof process . argv0 === 'string' &&
22- process . argv0 . length > 0
23- ? `unknown_service:${ process . argv0 } `
24- : 'unknown_service' ;
17+ let serviceName : string | undefined ;
2518
19+ // Property name accessed dynamically to avoid browser/Edge Runtime static analysis warnings
20+ const ARGV0 = 'argv0' ;
21+
22+ /**
23+ * Returns the default service name for OpenTelemetry resources.
24+ * In Node.js environments, returns "unknown_service:<process.argv0>".
25+ * In browser/edge environments, returns "unknown_service".
26+ */
2627export function defaultServiceName ( ) : string {
27- return DEFAULT_SERVICE_NAME ;
28+ if ( serviceName === undefined ) {
29+ const argv0 = typeof process === 'object' ? process [ ARGV0 ] : undefined ;
30+ serviceName =
31+ typeof argv0 === 'string' && argv0 . length > 0
32+ ? `unknown_service:${ argv0 } `
33+ : 'unknown_service' ;
34+ }
35+ return serviceName ;
2836}
You can’t perform that action at this time.
0 commit comments