Skip to content

Commit

Permalink
chore: modify ItraceParentContext to SpanContext instead
Browse files Browse the repository at this point in the history
  • Loading branch information
razbroc committed Jul 29, 2024
1 parent b96600e commit 4a5b401
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
16 changes: 6 additions & 10 deletions src/common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BBox, FeatureCollection, Geometry } from '@turf/helpers';
import { ICreateJobBody, ICreateTaskBody, IJobResponse, ITaskResponse, OperationStatus } from '@map-colonies/mc-priority-queue';
import { IHttpRetryConfig, ITileRange } from '@map-colonies/mc-utils';
import { TileOutputFormat } from '@map-colonies/mc-model-types';
import { SpanContext } from '@opentelemetry/api';
import { ArtifactType, TileFormatStrategy } from './enums';

export interface IConfig {
Expand Down Expand Up @@ -52,7 +53,7 @@ export interface IWorkerExportInput {
roi: FeatureCollection;
fileNamesTemplates: ILinkDefinition;
description?: string;
traceContext: ITraceParentContext;
traceContext: SpanContext;
}

export interface IBasicResponse {
Expand All @@ -64,7 +65,7 @@ export interface ICreateExportJobResponse {
taskIds: string[];
status: OperationStatus.IN_PROGRESS | OperationStatus.COMPLETED;
isDuplicated?: boolean;
traceContext?: ITraceParentContext;
traceContext?: SpanContext;
}

export interface ICallbackExportData {
Expand Down Expand Up @@ -116,13 +117,13 @@ export interface IJobExportParameters {
fileNamesTemplates: ILinkDefinition;
gpkgEstimatedSize?: number;
cleanupData?: ICleanupData;
traceContext?: ITraceParentContext;
traceContext?: SpanContext;
}

export interface ITaskFinalizeParameters {
reason?: string;
exporterTaskStatus: OperationStatus;
traceParentContext?: ITraceParentContext;
traceParentContext?: SpanContext;
}

export declare type MergerSourceType = 'S3' | 'GPKG' | 'FS';
Expand All @@ -143,7 +144,7 @@ export interface ITaskParameters {
outputFormatStrategy?: TileFormatStrategy;
batches: ITileRange[];
sources: IMapSource[];
traceParentContext?: ITraceParentContext;
traceParentContext?: SpanContext;
}

export interface IExportJobStatusResponse {
Expand Down Expand Up @@ -223,8 +224,3 @@ export interface IExternalClientsConfig {
httpRetry: IHttpRetryConfig;
disableHttpClientLogs: boolean;
}

export interface ITraceParentContext {
traceId: string;
spanId: string;
}
3 changes: 2 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export function createSpanMetadata(
spanKind?: SpanKind,
context?: { traceId: string; spanId: string }
): { traceContext: SpanContext | undefined; spanOptions: SpanOptions | undefined } {
const FLAG_SAMPLED = 1;
if (!context) {
return { spanOptions: undefined, traceContext: undefined };
}
Expand Down Expand Up @@ -134,3 +133,5 @@ export const parseFeatureCollection = (featuresCollection: FeatureCollection): I
});
return parsedGeoRecord;
};

export const FLAG_SAMPLED = 1; // 00000001
9 changes: 6 additions & 3 deletions src/createPackage/models/createPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
parseFeatureCollection,
generateGeoIdentifier,
getFilesha256Hash,
FLAG_SAMPLED,
} from '../../common/utils';
import { RasterCatalogManagerClient } from '../../clients/rasterCatalogManagerClient';
import { DEFAULT_CRS, DEFAULT_PRIORITY, SERVICES } from '../../common/constants';
Expand Down Expand Up @@ -183,8 +184,7 @@ export class CreatePackageManager {
);
if (!record.sanitizedBox) {
throw new BadRequestError(
`Requested ${JSON.stringify(record.geometry as Polygon | MultiPolygon)} has no intersection with requested layer ${
layer.metadata.id as string
`Requested ${JSON.stringify(record.geometry as Polygon | MultiPolygon)} has no intersection with requested layer ${layer.metadata.id as string
}`
);
}
Expand Down Expand Up @@ -291,7 +291,10 @@ export class CreatePackageManager {
gpkgEstimatedSize: estimatesGpkgSize,
description,
targetFormat: layerMetadata.tileOutputFormat,
traceContext: mainTraceIds,
traceContext: {
...mainTraceIds,
traceFlags: FLAG_SAMPLED
},
outputFormatStrategy: TileFormatStrategy.MIXED,
};
const jobCreated = await this.jobManagerClient.createExport(workerInput);
Expand Down
2 changes: 1 addition & 1 deletion src/finalizationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class FinalizationManager {

if (attempts <= this.finalizeAttempts) {
const isSuccess = finalizeTask.parameters.exporterTaskStatus === OperationStatus.COMPLETED ? true : false;
let errReason = finalizeTask.parameters.reason;כ
let errReason = finalizeTask.parameters.reason;

// finalizing job-task by exporting state [gpkg created or not]
if (isSuccess) {
Expand Down
2 changes: 2 additions & 0 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LayerMetadata, ProductType, RecordType, TileOutputFormat } from '@map-c
import { IJobResponse, OperationStatus } from '@map-colonies/mc-priority-queue';
import { FeatureCollection } from '@turf/helpers';
import { ICreatePackageRoi, IJobExportParameters, ITaskParameters, IWorkerExportInput } from '../../src/common/interfaces';
import { FLAG_SAMPLED } from '../../src/common/utils'
import { TileFormatStrategy } from '../../src/common/enums';

const layerMetadata: LayerMetadata = {
Expand Down Expand Up @@ -484,6 +485,7 @@ const workerExportInput: IWorkerExportInput = {
traceContext: {
spanId: '123',
traceId: '456',
traceFlags: FLAG_SAMPLED
},
};

Expand Down

0 comments on commit 4a5b401

Please sign in to comment.