Skip to content

Commit 762af17

Browse files
authored
fix: enhanced typescript support for currentSpan().span (#1370)
- typing showed an error when accessing `instana.currentSpan().span` - defined the inner span attribute via TS - more TS & SDK improvements are coming soon
1 parent 8df5f48 commit 762af17

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

packages/collector/src/types/shared.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CollectorConfig } from './collector';
22
import { GenericLogger, InstanaBaseSpan } from '@instana/core/src/core';
33

44
export interface Init {
5-
currentSpan(): InstanaBaseSpan;
5+
currentSpan(): { span: InstanaBaseSpan };
66
isTracing(): boolean;
77
isConnected(): boolean;
88
setLogger(logger: GenericLogger): void;
@@ -15,13 +15,13 @@ export interface Init {
1515

1616
export type InitFunction = {
1717
(config?: CollectorConfig): Init;
18-
sdk: any;
18+
currentSpan(): { span: InstanaBaseSpan };
19+
isTracing(): boolean;
20+
isConnected(): boolean;
21+
setLogger(logger: GenericLogger): void;
1922
core: any;
20-
currentSpan: any;
21-
isTracing: any;
22-
isConnected: any;
23-
setLogger: any;
2423
sharedMetrics: any;
2524
experimental: any;
2625
opentracing: any;
26+
sdk: any;
2727
};

packages/collector/test/tracing/misc/typescript/ts_cjs/src/app_1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
2828
app.get('/request', async (req, res) => {
2929
const currentSpan = instana.currentSpan();
3030

31-
if (!currentSpan) {
31+
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
3232
throw new Error('No current span available.');
3333
}
3434

packages/collector/test/tracing/misc/typescript/ts_cjs/src/app_2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
2828
app.get('/request', async (req, res) => {
2929
const currentSpan = instana.currentSpan();
3030

31-
if (!currentSpan) {
31+
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
3232
throw new Error('No current span available.');
3333
}
3434

packages/collector/test/tracing/misc/typescript/ts_esm/src/app_1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
2828
app.get('/request', async (req, res) => {
2929
const currentSpan = instana.currentSpan();
3030

31-
if (!currentSpan) {
31+
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
3232
throw new Error('No current span available.');
3333
}
3434

packages/collector/test/tracing/misc/typescript/ts_esm/src/app_2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
2828
app.get('/request', async (req, res) => {
2929
const currentSpan = instana.default.currentSpan();
3030

31-
if (!currentSpan) {
31+
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
3232
throw new Error('No current span available.');
3333
}
3434

packages/collector/test/tracing/misc/typescript/ts_esm/ts_esm_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const loaderPath = isLatestEsmSupportedVersion(process.versions.node)
2525
mochaSuiteFn('Typescript TS->ESM', function () {
2626
this.timeout(config.getTestTimeout() * 5);
2727

28-
mochaSuiteFn('[CASE 1]', () => {
28+
describe('[CASE 1]', () => {
2929
globalAgent.setUpCleanUpHooks();
3030
const agentControls = globalAgent.instance;
3131

@@ -68,7 +68,7 @@ mochaSuiteFn('Typescript TS->ESM', function () {
6868
});
6969
});
7070

71-
mochaSuiteFn('[CASE 2]', () => {
71+
describe('[CASE 2]', () => {
7272
globalAgent.setUpCleanUpHooks();
7373
const agentControls = globalAgent.instance;
7474

0 commit comments

Comments
 (0)