Skip to content

Commit

Permalink
fix: enhanced typescript support for currentSpan().span (#1370)
Browse files Browse the repository at this point in the history
- typing showed an error when accessing `instana.currentSpan().span`
- defined the inner span attribute via TS
- more TS & SDK improvements are coming soon
  • Loading branch information
kirrg001 authored Oct 9, 2024
1 parent 8df5f48 commit 762af17
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/collector/src/types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CollectorConfig } from './collector';
import { GenericLogger, InstanaBaseSpan } from '@instana/core/src/core';

export interface Init {
currentSpan(): InstanaBaseSpan;
currentSpan(): { span: InstanaBaseSpan };
isTracing(): boolean;
isConnected(): boolean;
setLogger(logger: GenericLogger): void;
Expand All @@ -15,13 +15,13 @@ export interface Init {

export type InitFunction = {
(config?: CollectorConfig): Init;
sdk: any;
currentSpan(): { span: InstanaBaseSpan };
isTracing(): boolean;
isConnected(): boolean;
setLogger(logger: GenericLogger): void;
core: any;
currentSpan: any;
isTracing: any;
isConnected: any;
setLogger: any;
sharedMetrics: any;
experimental: any;
opentracing: any;
sdk: any;
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
app.get('/request', async (req, res) => {
const currentSpan = instana.currentSpan();

if (!currentSpan) {
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
throw new Error('No current span available.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
app.get('/request', async (req, res) => {
const currentSpan = instana.currentSpan();

if (!currentSpan) {
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
throw new Error('No current span available.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
app.get('/request', async (req, res) => {
const currentSpan = instana.currentSpan();

if (!currentSpan) {
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
throw new Error('No current span available.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app.get('/', async (req, res) => {
app.get('/request', async (req, res) => {
const currentSpan = instana.default.currentSpan();

if (!currentSpan) {
if (!currentSpan || !currentSpan.span || !currentSpan.span.t) {
throw new Error('No current span available.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const loaderPath = isLatestEsmSupportedVersion(process.versions.node)
mochaSuiteFn('Typescript TS->ESM', function () {
this.timeout(config.getTestTimeout() * 5);

mochaSuiteFn('[CASE 1]', () => {
describe('[CASE 1]', () => {
globalAgent.setUpCleanUpHooks();
const agentControls = globalAgent.instance;

Expand Down Expand Up @@ -68,7 +68,7 @@ mochaSuiteFn('Typescript TS->ESM', function () {
});
});

mochaSuiteFn('[CASE 2]', () => {
describe('[CASE 2]', () => {
globalAgent.setUpCleanUpHooks();
const agentControls = globalAgent.instance;

Expand Down

0 comments on commit 762af17

Please sign in to comment.