Skip to content

Commit 3ba871e

Browse files
chore: linting
1 parent 3bcb862 commit 3ba871e

12 files changed

Lines changed: 36 additions & 46 deletions

docs/guides/trace_and_monitor_basic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ await crawler.run(['https://crawlee.dev']);
1919
// Ensure all telemetry is flushed before exiting
2020
await sdk.shutdown();
2121
console.log('Crawl complete. View traces at http://localhost:16686');
22-

docs/guides/trace_and_monitor_custom.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ export const sdk = new NodeSDK({
6060
});
6161

6262
sdk.start();
63-

docs/guides/trace_and_monitor_setup.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
55
import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';
66
import { NodeSDK } from '@opentelemetry/sdk-node';
77
import { CrawleeInstrumentation } from '@crawlee/otel';
8-
import {
9-
ATTR_SERVICE_NAME,
10-
ATTR_SERVICE_VERSION,
11-
} from '@opentelemetry/semantic-conventions';
8+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
129

1310
// Create a resource that identifies your service
1411
const resource = resourceFromAttributes({
@@ -47,4 +44,3 @@ process.on('SIGTERM', async () => {
4744
await sdk.shutdown();
4845
process.exit(0);
4946
});
50-

docs/guides/trace_and_monitor_wrap_with_span.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,3 @@ const crawler = new CheerioCrawler({
8383
});
8484

8585
await crawler.run(['https://crawlee.dev']);
86-

packages/otel/src/constants.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ export const requestHandlingInstrumentationMethods: ClassMethodToInstrument[] =
5858
className: 'BrowserCrawler',
5959
methodName: '_runRequestHandler',
6060
spanName: 'crawlee.browser.runRequestHandler',
61-
spanOptions(context: any) { // Request context from BrowserCrawler
62-
return { attributes: {
63-
'crawlee.request.id': context.request.id,
64-
'crawlee.request.url': context.request.url,
65-
'crawlee.request.method': context.request.method,
66-
'crawlee.request.retry_count': context.request.retryCount,
67-
}}
61+
spanOptions(context: any) {
62+
// Request context from BrowserCrawler
63+
return {
64+
attributes: {
65+
'crawlee.request.id': context.request.id,
66+
'crawlee.request.url': context.request.url,
67+
'crawlee.request.method': context.request.method,
68+
'crawlee.request.retry_count': context.request.retryCount,
69+
},
70+
};
6871
},
6972
},
7073
{
@@ -78,22 +81,24 @@ export const requestHandlingInstrumentationMethods: ClassMethodToInstrument[] =
7881
className: 'HttpCrawler',
7982
methodName: '_runRequestHandler',
8083
spanName: 'crawlee.http.runRequestHandler',
81-
spanOptions(context: any) { // Request context from HttpCrawler
82-
return { attributes: {
83-
'crawlee.request.id': context.request.id,
84-
'crawlee.request.url': context.request.url,
85-
'crawlee.request.method': context.request.method,
86-
'crawlee.request.retry_count': context.request.retryCount,
87-
}}
84+
spanOptions(context: any) {
85+
// Request context from HttpCrawler
86+
return {
87+
attributes: {
88+
'crawlee.request.id': context.request.id,
89+
'crawlee.request.url': context.request.url,
90+
'crawlee.request.method': context.request.method,
91+
'crawlee.request.retry_count': context.request.retryCount,
92+
},
93+
};
8894
},
8995
},
9096
] as const;
9197

92-
9398
/**
9499
* Maps Apify log levels to OpenTelemetry severity numbers.
95100
* See https://github.com/apify/apify-shared-js/blob/83d46cf72a338ff671f89dcbc2b0db7dd571e29f/packages/log/src/log_consts.ts#L1
96-
*
101+
*
97102
* ```typescript
98103
* export enum LogLevel {
99104
* // Turns off logging completely
@@ -118,4 +123,4 @@ export const apifyLogLevelMap: Record<number, SeverityNumber> = {
118123
4: SeverityNumber.INFO,
119124
5: SeverityNumber.DEBUG,
120125
6: SeverityNumber.DEBUG,
121-
} as const;
126+
} as const;

packages/otel/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { CrawleeInstrumentation } from './instrumentation';
22
export * from './types';
3-
export { wrapWithSpan } from './utilities';
3+
export { wrapWithSpan } from './utilities';

packages/otel/src/instrumentation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,11 @@ export class CrawleeInstrumentation extends InstrumentationBase<CrawleeInstrumen
9393
instrumentation.logger.emit({
9494
severityNumber: apifyLogLevelMap[level],
9595
body: message,
96-
attributes: {...exception, ...data},
96+
attributes: { ...exception, ...data },
9797
});
9898
}
9999
return original.apply(this, [level, message, data, exception]);
100100
};
101101
};
102102
}
103103
}
104-
105-

packages/otel/src/utilities.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ export function wrapWithSpan<Args extends unknown[], Return>(
7979
): (...args: Args) => Return {
8080
return function (this: unknown, ...args: Args): Return {
8181
const tracer = options?.tracer ?? trace.getTracer('crawlee');
82-
const spanName = typeof options?.spanName === 'function'
83-
? options.spanName.apply(this, args)
84-
: options?.spanName ?? (fn.name || 'anonymous');
85-
const spanOptions = typeof options?.spanOptions === 'function'
86-
? options.spanOptions.apply(this, args)
87-
: options?.spanOptions ?? {};
82+
const spanName =
83+
typeof options?.spanName === 'function'
84+
? options.spanName.apply(this, args)
85+
: (options?.spanName ?? (fn.name || 'anonymous'));
86+
const spanOptions =
87+
typeof options?.spanOptions === 'function'
88+
? options.spanOptions.apply(this, args)
89+
: (options?.spanOptions ?? {});
8890

8991
return tracer.startActiveSpan(spanName, spanOptions, async (span) => {
9092
try {
@@ -100,4 +102,4 @@ export function wrapWithSpan<Args extends unknown[], Return>(
100102
}
101103
}) as Return;
102104
};
103-
}
105+
}

packages/otel/test/constants.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ describe('apifyLogLevelMap', () => {
5151
}
5252
});
5353
});
54-

packages/otel/test/instrumentation.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,3 @@ describe('requestHandlingInstrumentationMethods', () => {
241241
}
242242
});
243243
});
244-

0 commit comments

Comments
 (0)