@crawlee/otel 4.0.0-beta.210 → 4.0.0-beta.212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import type { InstrumentationModuleDefinition } from '@opentelemetry/instrumenta
3
3
  import { InstrumentationBase } from '@opentelemetry/instrumentation';
4
4
  import type { CrawleeInstrumentationConfig } from './types.js';
5
5
  export declare class CrawleeInstrumentation extends InstrumentationBase<CrawleeInstrumentationConfig> {
6
+ #private;
6
7
  constructor(config?: CrawleeInstrumentationConfig);
7
8
  /**
8
9
  * Shares the tracer with the exported `wrapWithSpan` helper, so that manually wrapped handlers end up in the same
@@ -17,21 +18,4 @@ export declare class CrawleeInstrumentation extends InstrumentationBase<CrawleeI
17
18
  setTracerProvider(tracerProvider: TracerProvider): void;
18
19
  protected init(): InstrumentationModuleDefinition[];
19
20
  private instantiateModuleDefinitions;
20
- /**
21
- * Resolves the prototype holding the method to patch, warning instead of throwing when the class or the method
22
- * is not there - a missing internal method must not break loading of the instrumented module.
23
- */
24
- private getPrototype;
25
- /** Mirrors {@link getPrototype}: only methods that were actually patched are restored. */
26
- private unwrapIfWrapped;
27
- private applyClassMethodPatch;
28
- private getLogPatch;
29
- /**
30
- * Emits one Crawlee log call as an OpenTelemetry log record.
31
- *
32
- * Everything here - reading the arguments, stringifying the message, handing the record to the SDK - runs inside
33
- * the application's own call to `log.info()` and friends, so a failure anywhere in it is reported and dropped
34
- * rather than raised.
35
- */
36
- private forwardLogRecord;
37
21
  }
@@ -54,34 +54,35 @@ export class CrawleeInstrumentation extends InstrumentationBase {
54
54
  if (this.getConfig().logInstrumentation) {
55
55
  definitions.push(crawleeModuleDefinition('@crawlee/core', (moduleExports) => {
56
56
  for (const method of loggerMethods) {
57
- const prototype = this.getPrototype(moduleExports, '@crawlee/core', 'BaseCrawleeLogger', method.methodName);
57
+ const prototype = this.#getPrototype(moduleExports, '@crawlee/core', 'BaseCrawleeLogger', method.methodName);
58
58
  if (prototype) {
59
- this._wrap(prototype, method.methodName, this.getLogPatch(method));
59
+ this._wrap(prototype, method.methodName, this.#getLogPatch(method));
60
60
  }
61
61
  }
62
62
  return moduleExports;
63
63
  }, (moduleExports) => {
64
64
  for (const method of loggerMethods) {
65
- this.unwrapIfWrapped(moduleExports?.BaseCrawleeLogger?.prototype, method.methodName);
65
+ this.#unwrapIfWrapped(moduleExports?.BaseCrawleeLogger?.prototype, method.methodName);
66
66
  }
67
67
  return moduleExports;
68
68
  }));
69
69
  }
70
70
  return definitions;
71
71
  }
72
+ // oxlint-disable-next-line crawlee/prefer-private-fields -- `InstrumentationBase`'s constructor calls `init()` before `#` members exist
72
73
  instantiateModuleDefinitions(moduleDefinitions) {
73
74
  return moduleDefinitions.map((definition) => {
74
75
  return crawleeModuleDefinition(definition.moduleName, (moduleExports) => {
75
76
  for (const patch of definition.classMethodPatches) {
76
- const prototype = this.getPrototype(moduleExports, definition.moduleName, patch.className, patch.methodName);
77
+ const prototype = this.#getPrototype(moduleExports, definition.moduleName, patch.className, patch.methodName);
77
78
  if (prototype) {
78
- this._wrap(prototype, patch.methodName, this.applyClassMethodPatch(patch));
79
+ this._wrap(prototype, patch.methodName, this.#applyClassMethodPatch(patch));
79
80
  }
80
81
  }
81
82
  return moduleExports;
82
83
  }, (moduleExports) => {
83
84
  for (const patch of definition.classMethodPatches) {
84
- this.unwrapIfWrapped(moduleExports?.[patch.className]?.prototype, patch.methodName);
85
+ this.#unwrapIfWrapped(moduleExports?.[patch.className]?.prototype, patch.methodName);
85
86
  }
86
87
  return moduleExports;
87
88
  });
@@ -91,7 +92,7 @@ export class CrawleeInstrumentation extends InstrumentationBase {
91
92
  * Resolves the prototype holding the method to patch, warning instead of throwing when the class or the method
92
93
  * is not there - a missing internal method must not break loading of the instrumented module.
93
94
  */
94
- getPrototype(moduleExports, moduleName, className, methodName) {
95
+ #getPrototype(moduleExports, moduleName, className, methodName) {
95
96
  const prototype = moduleExports?.[className]?.prototype;
96
97
  if (typeof prototype?.[methodName] !== 'function') {
97
98
  this._diag.warn(`Skipping instrumentation of ${moduleName}: ${className}.${methodName} was not found. ` +
@@ -100,13 +101,13 @@ export class CrawleeInstrumentation extends InstrumentationBase {
100
101
  }
101
102
  return prototype;
102
103
  }
103
- /** Mirrors {@link getPrototype}: only methods that were actually patched are restored. */
104
- unwrapIfWrapped(prototype, methodName) {
104
+ /** Mirrors `#getPrototype`: only methods that were actually patched are restored. */
105
+ #unwrapIfWrapped(prototype, methodName) {
105
106
  if (prototype && isWrapped(prototype[methodName])) {
106
107
  this._unwrap(prototype, methodName);
107
108
  }
108
109
  }
109
- applyClassMethodPatch(patch) {
110
+ #applyClassMethodPatch(patch) {
110
111
  const { spanName, spanOptions } = patch;
111
112
  const qualifiedName = `${patch.className}.${patch.methodName}`;
112
113
  const codeAttributes = { [ATTR_CODE_FUNCTION_NAME]: qualifiedName };
@@ -124,7 +125,7 @@ export class CrawleeInstrumentation extends InstrumentationBase {
124
125
  });
125
126
  };
126
127
  }
127
- getLogPatch(method) {
128
+ #getLogPatch(method) {
128
129
  // oxlint-disable-next-line no-this-alias
129
130
  const instrumentation = this;
130
131
  return function wrapLog(original) {
@@ -136,7 +137,7 @@ export class CrawleeInstrumentation extends InstrumentationBase {
136
137
  original.apply(this, args);
137
138
  }
138
139
  finally {
139
- instrumentation.forwardLogRecord(method, args);
140
+ instrumentation.#forwardLogRecord(method, args);
140
141
  }
141
142
  };
142
143
  };
@@ -148,7 +149,7 @@ export class CrawleeInstrumentation extends InstrumentationBase {
148
149
  * the application's own call to `log.info()` and friends, so a failure anywhere in it is reported and dropped
149
150
  * rather than raised.
150
151
  */
151
- forwardLogRecord(method, args) {
152
+ #forwardLogRecord(method, args) {
152
153
  try {
153
154
  const { message, data } = method.read(args);
154
155
  // Crawlee leaves level filtering to the logging library, so everything is forwarded and the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/otel",
3
- "version": "4.0.0-beta.210",
3
+ "version": "4.0.0-beta.212",
4
4
  "description": "OpenTelemetry instrumentation for Crawlee",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -60,5 +60,5 @@
60
60
  }
61
61
  }
62
62
  },
63
- "gitHead": "037dff5d651d88e96749cc79d17bc6d1e154f4e1"
63
+ "gitHead": "171a63a5d7f2a6d74cbce58479204ac20d30b87e"
64
64
  }