Skip to content

Commit

Permalink
fix(tracer): modify aws-xray-sdk-core import for js (#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Mar 5, 2024
1 parent 303428a commit 29630b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/tracer/src/Tracer.ts
Expand Up @@ -17,7 +17,9 @@ import type {
} from './types/Tracer.js';
import { ProviderService } from './provider/ProviderService.js';
import type { ProviderServiceInterface } from './types/ProviderServiceInterface.js';
import { type Segment, Subsegment } from 'aws-xray-sdk-core';
import type { Segment, Subsegment } from 'aws-xray-sdk-core';
import xraySdk from 'aws-xray-sdk-core';
const { Subsegment: XraySubsegment } = xraySdk;

/**
* ## Intro
Expand Down Expand Up @@ -578,7 +580,7 @@ class Tracer extends Utility implements TracerInterface {
*/
public getSegment(): Segment | Subsegment | undefined {
if (!this.isTracingEnabled()) {
return new Subsegment('## Dummy segment');
return new XraySubsegment('## Dummy segment');
}
const segment = this.provider.getSegment();
if (segment === undefined) {
Expand Down
14 changes: 7 additions & 7 deletions packages/tracer/src/provider/ProviderService.ts
Expand Up @@ -3,7 +3,9 @@ import type {
ProviderServiceInterface,
ContextMissingStrategy,
} from '../types/ProviderServiceInterface.js';
import {
import type { Segment, Subsegment, Logger } from 'aws-xray-sdk-core';
import xraySdk from 'aws-xray-sdk-core';
const {
captureAWS,
captureAWSClient,
captureAWSv3Client,
Expand All @@ -13,13 +15,11 @@ import {
getNamespace,
getSegment,
setSegment,
Segment,
Subsegment,
Segment: XraySegment,
setContextMissingStrategy,
setDaemonAddress,
setLogger,
Logger,
} from 'aws-xray-sdk-core';
} = xraySdk;
import { addUserAgentMiddleware } from '@aws-lambda-powertools/commons';

class ProviderService implements ProviderServiceInterface {
Expand Down Expand Up @@ -79,7 +79,7 @@ class ProviderService implements ProviderServiceInterface {

return;
}
if (segment instanceof Segment) {
if (segment instanceof XraySegment) {
console.warn(
'You cannot annotate the main segment in a Lambda execution environment'
);
Expand All @@ -98,7 +98,7 @@ class ProviderService implements ProviderServiceInterface {

return;
}
if (segment instanceof Segment) {
if (segment instanceof XraySegment) {
console.warn(
'You cannot add metadata to the main segment in a Lambda execution environment'
);
Expand Down

0 comments on commit 29630b5

Please sign in to comment.