|
1 | 1 | import * as OpenTelemetry from '@opentelemetry/api';
|
| 2 | +import { SpanKind } from '@opentelemetry/api'; |
2 | 3 | import { Resource } from '@opentelemetry/resources';
|
3 | 4 | import { Span as OtelSpan } from '@opentelemetry/sdk-trace-base';
|
4 | 5 | import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
@@ -328,6 +329,162 @@ describe('SentrySpanProcessor', () => {
|
328 | 329 | expect(transaction?.status).toBe(expected);
|
329 | 330 | },
|
330 | 331 | );
|
| 332 | + |
| 333 | + it('updates op/description for span on end', async () => { |
| 334 | + const tracer = provider.getTracer('default'); |
| 335 | + |
| 336 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 337 | + tracer.startActiveSpan('SELECT * FROM users;', child => { |
| 338 | + const sentrySpan = getSpanForOtelSpan(child); |
| 339 | + |
| 340 | + child.updateName('new name'); |
| 341 | + |
| 342 | + expect(sentrySpan?.op).toBe(undefined); |
| 343 | + expect(sentrySpan?.description).toBe('SELECT * FROM users;'); |
| 344 | + |
| 345 | + child.end(); |
| 346 | + |
| 347 | + expect(sentrySpan?.op).toBe(undefined); |
| 348 | + expect(sentrySpan?.description).toBe('new name'); |
| 349 | + |
| 350 | + parentOtelSpan.end(); |
| 351 | + }); |
| 352 | + }); |
| 353 | + }); |
| 354 | + |
| 355 | + it('updates op/description based on attributes for HTTP_METHOD for client', async () => { |
| 356 | + const tracer = provider.getTracer('default'); |
| 357 | + |
| 358 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 359 | + tracer.startActiveSpan('/users/all', { kind: SpanKind.CLIENT }, child => { |
| 360 | + const sentrySpan = getSpanForOtelSpan(child); |
| 361 | + |
| 362 | + child.setAttribute(SemanticAttributes.HTTP_METHOD, 'GET'); |
| 363 | + |
| 364 | + child.end(); |
| 365 | + |
| 366 | + expect(sentrySpan?.op).toBe('http.client'); |
| 367 | + expect(sentrySpan?.description).toBe('GET /users/all'); |
| 368 | + |
| 369 | + parentOtelSpan.end(); |
| 370 | + }); |
| 371 | + }); |
| 372 | + }); |
| 373 | + |
| 374 | + it('updates op/description based on attributes for HTTP_METHOD for server', async () => { |
| 375 | + const tracer = provider.getTracer('default'); |
| 376 | + |
| 377 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 378 | + tracer.startActiveSpan('/users/all', { kind: SpanKind.SERVER }, child => { |
| 379 | + const sentrySpan = getSpanForOtelSpan(child); |
| 380 | + |
| 381 | + child.setAttribute(SemanticAttributes.HTTP_METHOD, 'GET'); |
| 382 | + |
| 383 | + child.end(); |
| 384 | + |
| 385 | + expect(sentrySpan?.op).toBe('http.server'); |
| 386 | + expect(sentrySpan?.description).toBe('GET /users/all'); |
| 387 | + |
| 388 | + parentOtelSpan.end(); |
| 389 | + }); |
| 390 | + }); |
| 391 | + }); |
| 392 | + |
| 393 | + it('updates op/description based on attributes for DB_SYSTEM', async () => { |
| 394 | + const tracer = provider.getTracer('default'); |
| 395 | + |
| 396 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 397 | + tracer.startActiveSpan('fetch users from DB', child => { |
| 398 | + const sentrySpan = getSpanForOtelSpan(child); |
| 399 | + |
| 400 | + child.setAttribute(SemanticAttributes.DB_SYSTEM, 'MySQL'); |
| 401 | + child.setAttribute(SemanticAttributes.DB_STATEMENT, 'SELECT * FROM users'); |
| 402 | + |
| 403 | + child.end(); |
| 404 | + |
| 405 | + expect(sentrySpan?.op).toBe('db'); |
| 406 | + expect(sentrySpan?.description).toBe('SELECT * FROM users'); |
| 407 | + |
| 408 | + parentOtelSpan.end(); |
| 409 | + }); |
| 410 | + }); |
| 411 | + }); |
| 412 | + |
| 413 | + it('updates op/description based on attributes for DB_SYSTEM without DB_STATEMENT', async () => { |
| 414 | + const tracer = provider.getTracer('default'); |
| 415 | + |
| 416 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 417 | + tracer.startActiveSpan('fetch users from DB', child => { |
| 418 | + const sentrySpan = getSpanForOtelSpan(child); |
| 419 | + |
| 420 | + child.setAttribute(SemanticAttributes.DB_SYSTEM, 'MySQL'); |
| 421 | + |
| 422 | + child.end(); |
| 423 | + |
| 424 | + expect(sentrySpan?.op).toBe('db'); |
| 425 | + expect(sentrySpan?.description).toBe('fetch users from DB'); |
| 426 | + |
| 427 | + parentOtelSpan.end(); |
| 428 | + }); |
| 429 | + }); |
| 430 | + }); |
| 431 | + |
| 432 | + it('updates op/description based on attributes for RPC_SERVICE', async () => { |
| 433 | + const tracer = provider.getTracer('default'); |
| 434 | + |
| 435 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 436 | + tracer.startActiveSpan('test operation', child => { |
| 437 | + const sentrySpan = getSpanForOtelSpan(child); |
| 438 | + |
| 439 | + child.setAttribute(SemanticAttributes.RPC_SERVICE, 'rpc service'); |
| 440 | + |
| 441 | + child.end(); |
| 442 | + |
| 443 | + expect(sentrySpan?.op).toBe('rpc'); |
| 444 | + expect(sentrySpan?.description).toBe('test operation'); |
| 445 | + |
| 446 | + parentOtelSpan.end(); |
| 447 | + }); |
| 448 | + }); |
| 449 | + }); |
| 450 | + |
| 451 | + it('updates op/description based on attributes for MESSAGING_SYSTEM', async () => { |
| 452 | + const tracer = provider.getTracer('default'); |
| 453 | + |
| 454 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 455 | + tracer.startActiveSpan('test operation', child => { |
| 456 | + const sentrySpan = getSpanForOtelSpan(child); |
| 457 | + |
| 458 | + child.setAttribute(SemanticAttributes.MESSAGING_SYSTEM, 'messaging system'); |
| 459 | + |
| 460 | + child.end(); |
| 461 | + |
| 462 | + expect(sentrySpan?.op).toBe('message'); |
| 463 | + expect(sentrySpan?.description).toBe('test operation'); |
| 464 | + |
| 465 | + parentOtelSpan.end(); |
| 466 | + }); |
| 467 | + }); |
| 468 | + }); |
| 469 | + |
| 470 | + it('updates op/description based on attributes for FAAS_TRIGGER', async () => { |
| 471 | + const tracer = provider.getTracer('default'); |
| 472 | + |
| 473 | + tracer.startActiveSpan('GET /users', parentOtelSpan => { |
| 474 | + tracer.startActiveSpan('test operation', child => { |
| 475 | + const sentrySpan = getSpanForOtelSpan(child); |
| 476 | + |
| 477 | + child.setAttribute(SemanticAttributes.FAAS_TRIGGER, 'test faas trigger'); |
| 478 | + |
| 479 | + child.end(); |
| 480 | + |
| 481 | + expect(sentrySpan?.op).toBe('test faas trigger'); |
| 482 | + expect(sentrySpan?.description).toBe('test operation'); |
| 483 | + |
| 484 | + parentOtelSpan.end(); |
| 485 | + }); |
| 486 | + }); |
| 487 | + }); |
331 | 488 | });
|
332 | 489 |
|
333 | 490 | // OTEL expects a custom date format
|
|
0 commit comments