22// SPDX-License-Identifier: Apache-2.0
33
44import { Resource } from '@opentelemetry/resources' ;
5- import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' ;
5+ import { SEMRESATTRS_SERVICE_NAME , SEMRESATTRS_SERVICE_VERSION } from '@opentelemetry/semantic-conventions' ;
66import { expect } from 'chai' ;
77import Sinon from 'sinon' ;
88import sinon from 'sinon' ;
@@ -57,11 +57,12 @@ describe('service name fallback', () => {
5757 } ) ;
5858 } ) ;
5959
60- it ( 'sets a service name based on package.json attributes' , async ( ) => {
60+ it ( 'sets a service name and version based on package.json attributes' , async ( ) => {
6161 givenAValidPackageJsonFile ( ) ;
6262 const result = serviceNameFallback . detect ( ) ;
6363 const attributes = await waitForAsyncDetection ( result ) ;
64- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ; 64+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
65+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
6566 } ) ;
6667
6768 it ( 'does not set a service name if DASH0_AUTOMATIC_SERVICE_NAME is false' , async ( ) => {
@@ -85,7 +86,8 @@ describe('service name fallback', () => {
8586 process . env . OTEL_SERVICE_NAME = ' ' ;
8687 const result = serviceNameFallback . detect ( ) ;
8788 const attributes = await waitForAsyncDetection ( result ) ;
88- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ; 89+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
90+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
8991 } ) ;
9092
9193 it ( 'does not set a service name if OTEL_RESOURCE_ATTRIBUTES has the service.name key' , async ( ) => {
@@ -101,7 +103,8 @@ describe('service name fallback', () => {
101103 process . env . OTEL_RESOURCE_ATTRIBUTES = 'key1=value,key2=value' ;
102104 const result = serviceNameFallback . detect ( ) ;
103105 const attributes = await waitForAsyncDetection ( result ) ;
104- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ; 106+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
107+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
105108 } ) ;
106109
107110 it ( 'does not set a service name if no package.json can be found' , async ( ) => {
0 commit comments