From 4a5b40195f1fcabe48094b899e6fec9135420c13 Mon Sep 17 00:00:00 2001 From: razbroc Date: Mon, 29 Jul 2024 12:04:54 +0300 Subject: [PATCH] chore: modify ItraceParentContext to SpanContext instead --- src/common/interfaces.ts | 16 ++++++---------- src/common/utils.ts | 3 ++- src/createPackage/models/createPackageManager.ts | 9 ++++++--- src/finalizationManager.ts | 2 +- tests/mocks/data.ts | 2 ++ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/common/interfaces.ts b/src/common/interfaces.ts index e8fdb0e..7bc55a8 100644 --- a/src/common/interfaces.ts +++ b/src/common/interfaces.ts @@ -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 { @@ -52,7 +53,7 @@ export interface IWorkerExportInput { roi: FeatureCollection; fileNamesTemplates: ILinkDefinition; description?: string; - traceContext: ITraceParentContext; + traceContext: SpanContext; } export interface IBasicResponse { @@ -64,7 +65,7 @@ export interface ICreateExportJobResponse { taskIds: string[]; status: OperationStatus.IN_PROGRESS | OperationStatus.COMPLETED; isDuplicated?: boolean; - traceContext?: ITraceParentContext; + traceContext?: SpanContext; } export interface ICallbackExportData { @@ -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'; @@ -143,7 +144,7 @@ export interface ITaskParameters { outputFormatStrategy?: TileFormatStrategy; batches: ITileRange[]; sources: IMapSource[]; - traceParentContext?: ITraceParentContext; + traceParentContext?: SpanContext; } export interface IExportJobStatusResponse { @@ -223,8 +224,3 @@ export interface IExternalClientsConfig { httpRetry: IHttpRetryConfig; disableHttpClientLogs: boolean; } - -export interface ITraceParentContext { - traceId: string; - spanId: string; -} diff --git a/src/common/utils.ts b/src/common/utils.ts index 6b46a71..282879d 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -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 }; } @@ -134,3 +133,5 @@ export const parseFeatureCollection = (featuresCollection: FeatureCollection): I }); return parsedGeoRecord; }; + +export const FLAG_SAMPLED = 1; // 00000001 diff --git a/src/createPackage/models/createPackageManager.ts b/src/createPackage/models/createPackageManager.ts index b55edf4..942e043 100644 --- a/src/createPackage/models/createPackageManager.ts +++ b/src/createPackage/models/createPackageManager.ts @@ -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'; @@ -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 }` ); } @@ -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); diff --git a/src/finalizationManager.ts b/src/finalizationManager.ts index 26b285d..cfc61a6 100644 --- a/src/finalizationManager.ts +++ b/src/finalizationManager.ts @@ -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) { diff --git a/tests/mocks/data.ts b/tests/mocks/data.ts index 8e65b66..2dc0c9a 100644 --- a/tests/mocks/data.ts +++ b/tests/mocks/data.ts @@ -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 = { @@ -484,6 +485,7 @@ const workerExportInput: IWorkerExportInput = { traceContext: { spanId: '123', traceId: '456', + traceFlags: FLAG_SAMPLED }, };