@@ -39,6 +39,7 @@ import {
3939 ATTR_SERVER_ADDRESS ,
4040 ATTR_SERVER_PORT ,
4141} from '@opentelemetry/semantic-conventions' ;
42+ import { SemconvStability } from '@opentelemetry/instrumentation' ;
4243
4344process . env . OTEL_SEMCONV_STABILITY_OPT_IN = 'database/dup' ;
4445const instrumentation = testUtils . registerInstrumentationTesting (
@@ -170,6 +171,66 @@ describe('redis v2-v3', () => {
170171 done ( ) ;
171172 } ) ;
172173 } ) ;
174+ describe ( 'semconv stability config' , ( ) => {
175+ function recordSetSpan ( cb : ( span : any ) => void ) {
176+ client . set ( 'covKey' , 'val' , ( err : unknown ) => {
177+ assert . ifError ( err ) ;
178+ const [ span ] = testUtils . getTestSpans ( ) ;
179+ cb ( span ) ;
180+ } ) ;
181+ }
182+ it ( 'should emit only old attributes when set to OLD' , done => {
183+ instrumentation . setConfig ( { semconvStability : SemconvStability . OLD } ) ;
184+
185+ recordSetSpan ( span => {
186+ assert . strictEqual ( span . attributes [ SEMATTRS_DB_SYSTEM ] , 'redis' ) ;
187+ assert . strictEqual (
188+ span . attributes [ SEMATTRS_DB_STATEMENT ] ,
189+ 'set covKey [1 other arguments]'
190+ ) ;
191+ assert . ok ( ! ( ATTR_DB_SYSTEM_NAME in span . attributes ) ) ;
192+ assert . ok ( ! ( ATTR_DB_QUERY_TEXT in span . attributes ) ) ;
193+ done ( ) ;
194+ } ) ;
195+ } ) ;
196+
197+ it ( 'should emit only new attributes when set to STABLE' , done => {
198+ instrumentation . setConfig ( {
199+ semconvStability : SemconvStability . STABLE ,
200+ } ) ;
201+
202+ recordSetSpan ( span => {
203+ assert . strictEqual ( span . attributes [ ATTR_DB_SYSTEM_NAME ] , 'redis' ) ;
204+ assert . strictEqual (
205+ span . attributes [ ATTR_DB_QUERY_TEXT ] ,
206+ 'set covKey [1 other arguments]'
207+ ) ;
208+ assert . ok ( ! ( SEMATTRS_DB_SYSTEM in span . attributes ) ) ;
209+ assert . ok ( ! ( SEMATTRS_DB_STATEMENT in span . attributes ) ) ;
210+ done ( ) ;
211+ } ) ;
212+ } ) ;
213+
214+ it ( 'should emit both old and new attributes when set to DUPLICATE' , done => {
215+ instrumentation . setConfig ( {
216+ semconvStability : SemconvStability . DUPLICATE ,
217+ } ) ;
218+
219+ recordSetSpan ( span => {
220+ assert . strictEqual ( span . attributes [ SEMATTRS_DB_SYSTEM ] , 'redis' ) ;
221+ assert . strictEqual (
222+ span . attributes [ SEMATTRS_DB_STATEMENT ] ,
223+ 'set covKey [1 other arguments]'
224+ ) ;
225+ assert . strictEqual ( span . attributes [ ATTR_DB_SYSTEM_NAME ] , 'redis' ) ;
226+ assert . strictEqual (
227+ span . attributes [ ATTR_DB_QUERY_TEXT ] ,
228+ 'set covKey [1 other arguments]'
229+ ) ;
230+ done ( ) ;
231+ } ) ;
232+ } ) ;
233+ } ) ;
173234
174235 describe ( 'Instrumenting query operations' , ( ) => {
175236 REDIS_OPERATIONS . forEach ( operation => {
0 commit comments