|
1 | 1 | import * as os from 'os';
|
2 | 2 | import { ProxyTracer } from '@opentelemetry/api';
|
3 | 3 | import * as opentelemetryInstrumentationPackage from '@opentelemetry/instrumentation';
|
4 |
| -import type { Event, EventHint } from '@sentry/core'; |
| 4 | +import type { Event, EventHint, Log } from '@sentry/core'; |
5 | 5 | import { SDK_VERSION, Scope, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core';
|
6 | 6 | import { setOpenTelemetryContextAsyncContextStrategy } from '@sentry/opentelemetry';
|
7 | 7 | import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest';
|
@@ -281,4 +281,32 @@ describe('NodeClient', () => {
|
281 | 281 | }),
|
282 | 282 | );
|
283 | 283 | });
|
| 284 | + |
| 285 | + describe('log capture', () => { |
| 286 | + it('adds server name to log attributes', () => { |
| 287 | + const options = getDefaultNodeClientOptions({ _experiments: { enableLogs: true } }); |
| 288 | + const client = new NodeClient(options); |
| 289 | + |
| 290 | + const log: Log = { level: 'info', message: 'test message', attributes: {} }; |
| 291 | + client.emit('beforeCaptureLog', log); |
| 292 | + |
| 293 | + expect(log.attributes).toEqual({ |
| 294 | + 'server.address': expect.any(String), |
| 295 | + }); |
| 296 | + }); |
| 297 | + |
| 298 | + it('preserves existing log attributes', () => { |
| 299 | + const serverName = 'test-server'; |
| 300 | + const options = getDefaultNodeClientOptions({ serverName, _experiments: { enableLogs: true } }); |
| 301 | + const client = new NodeClient(options); |
| 302 | + |
| 303 | + const log: Log = { level: 'info', message: 'test message', attributes: { 'existing.attr': 'value' } }; |
| 304 | + client.emit('beforeCaptureLog', log); |
| 305 | + |
| 306 | + expect(log.attributes).toEqual({ |
| 307 | + 'existing.attr': 'value', |
| 308 | + 'server.address': serverName, |
| 309 | + }); |
| 310 | + }); |
| 311 | + }); |
284 | 312 | });
|
0 commit comments