Skip to content

Commit

Permalink
update prototype patch (#55)
Browse files Browse the repository at this point in the history
* add prototype patch

* refactor patch

* add comment
  • Loading branch information
EddeCCC authored Mar 26, 2024
1 parent 5812f16 commit 646cb7a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 245 deletions.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ BOOMR.init({
scheduledDelayMillis: 500,
exportTimeoutMillis: 30000,
},
prototypeExporterPatch: true, // patches the OpenTelemetry collector-span-exporter in case the Prototype framework is used
commonAttributes: {
"application": "demo-app",
"stage": "prod"
Expand All @@ -132,28 +133,29 @@ BOOMR.init({
```
Available options are:

| Option | Description | Default value |
|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| `samplingRate` | Sampling rate to use when collecting spans. Value must be between `0` and `1`. | `1` |
| `corsUrls` | Array of CORS URLs to take into consideration when propagating trace information. By default, CORS URLs are excluded from the propagation. | `[]` |
| `collectorConfiguration` | Object that defines the OpenTelemetry collector configuration, like the URL to send spans to. See [OTLPExporterNodeConfigBase](https://www.npmjs.com/package/@opentelemetry/exporter-trace-otlp-http) interface for all options. | `undefined` |
| `consoleOnly` | If `true` spans will be logged on the console and not sent to the collector endpoint. | `false` |
| `plugins` | Object for enabling and disabling OpenTelemetry plugins. | |
| `plugins.instrument_fetch` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-fetch) for instrumentation of the fetch API. This will only be used in case the `fetch` API exists. | `true` |
| `plugins.instrument_xhr` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-xml-http-request) for instrumentation of the XMLHttpRequest API. | `true` |
| `plugins.instrument_document_load` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load) for instrumentation of the document load (initial request). | `true` |
| `plugins.instrument_user_interaction` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction) for instrumentation of user interactions. | `true` |
| `plugins.browser_detector` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-browser-detector) for detecting browser attributes. | `true` |
| `global_instrumentation` | Object for configuring additional instrumentations, which will be applied to every OpenTelemetry plugin. | |
| `global_instrumentation.requestParameter` | If enabled, existing request parameters will be added as attributes to spans and, if not excluded, will be added to the corresponding beacon as well. | |
| `exporter` | Object for configuring the span exporter. Only used if `consoleOnly` is not enabled. | |
| `exporter.maxQueueSize` | The maximum queue size. After the size is reached spans are dropped. | `100` |
| `exporter.maxExportBatchSize` | The maximum batch size of every export. It must be smaller or equal to `maxQueueSize`. | `10` |
| `exporter.scheduledDelayMillis` | The interval between two consecutive exports. | `500` |
| `exporter.exportTimeoutMillis` | How long the export can run before it is cancelled. | `30000` |
| `commonAttributes` | An Object defining common span attributes which will be added to each recorded span. | `{}` |
| `serviceName` | A `string` or function which can be used to set the spans' service name. A function can be defined for dynamically providing the service name, e.g. based on Boomerang values. | `undefined` |
| `propagationHeader` | Defines the format of the context propagation header. Available formats: `TRACE_CONTEXT`, `B3_SINGLE`, `B3_MULTI` | `TRACE_CONTEXT` |
| Option | Description | Default value |
|-------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| `samplingRate` | Sampling rate to use when collecting spans. Value must be between `0` and `1`. | `1` |
| `corsUrls` | Array of CORS URLs to take into consideration when propagating trace information. By default, CORS URLs are excluded from the propagation. | `[]` |
| `collectorConfiguration` | Object that defines the OpenTelemetry collector configuration, like the URL to send spans to. See [OTLPExporterNodeConfigBase](https://www.npmjs.com/package/@opentelemetry/exporter-trace-otlp-http) interface for all options. | `undefined` |
| `consoleOnly` | If `true` spans will be logged on the console and not sent to the collector endpoint. | `false` |
| `plugins` | Object for enabling and disabling OpenTelemetry plugins. | |
| `plugins.instrument_fetch` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-fetch) for instrumentation of the fetch API. This will only be used in case the `fetch` API exists. | `true` |
| `plugins.instrument_xhr` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-xml-http-request) for instrumentation of the XMLHttpRequest API. | `true` |
| `plugins.instrument_document_load` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load) for instrumentation of the document load (initial request). | `true` |
| `plugins.instrument_user_interaction` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction) for instrumentation of user interactions. | `true` |
| `plugins.browser_detector` | Enabling the [OpenTelemetry plugin](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-browser-detector) for detecting browser attributes. | `true` |
| `global_instrumentation` | Object for configuring additional instrumentations, which will be applied to every OpenTelemetry plugin. | |
| `global_instrumentation.requestParameter` | If enabled, existing request parameters will be added as attributes to spans and, if not excluded, will be added to the corresponding beacon as well. | |
| `exporter` | Object for configuring the span exporter. Only used if `consoleOnly` is not enabled. | |
| `exporter.maxQueueSize` | The maximum queue size. After the size is reached spans are dropped. | `100` |
| `exporter.maxExportBatchSize` | The maximum batch size of every export. It must be smaller or equal to `maxQueueSize`. | `10` |
| `exporter.scheduledDelayMillis` | The interval between two consecutive exports. | `500` |
| `exporter.exportTimeoutMillis` | How long the export can run before it is cancelled. | `30000` |
| `prototypeExporterPatch` | Patches the OpenTelemetry collector-span-exporter, so it is compatible with the Prototype framework. This is only necessary and should only be activated, when the Prototype framework is used. [For more information see the linked file](https://github.com/NovatecConsulting/boomerang-opentelemetry-plugin/blob/master/src/impl/patchCollectorPrototype.ts). | `false` |
| `commonAttributes` | An Object defining common span attributes which will be added to each recorded span. | `{}` |
| `serviceName` | A `string` or function which can be used to set the spans' service name. A function can be defined for dynamically providing the service name, e.g. based on Boomerang values. | `undefined` |
| `propagationHeader` | Defines the format of the context propagation header. Available formats: `TRACE_CONTEXT`, `B3_SINGLE`, `B3_MULTI` | `TRACE_CONTEXT` |

## Manual Instrumentation

Expand Down
11 changes: 5 additions & 6 deletions src/impl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { CustomXMLHttpRequestInstrumentation } from './instrumentation/xmlHttpRe
import { CustomFetchInstrumentation } from './instrumentation/fetchInstrumentation';
import { CustomUserInteractionInstrumentation } from './instrumentation/userInteractionInstrumentation';
import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector';
import { patchExporterClass } from './patchCollectorPrototype';

/**
* TODOs:
Expand Down Expand Up @@ -95,6 +96,7 @@ export default class OpenTelemetryTracingImpl {
scheduledDelayMillis: 500,
exportTimeoutMillis: 30000,
},
prototypeExporterPatch: true,
commonAttributes: {},
serviceName: undefined,
propagationHeader: PropagationHeader.TRACE_CONTEXT
Expand Down Expand Up @@ -159,13 +161,10 @@ export default class OpenTelemetryTracingImpl {

const exporter = new OTLPTraceExporter(collectorOptions);

// Patch is no longer necessary, since the new exporter does no longer use Array.from()
// TODO Remove patch after tested in production
// patches the collector-export in order to be compatible with Prototype.
// if (this.props.prototypeExporterPatch) {
// patchExporter(exporter);
// patchExporterClass();
// }
if (this.props.prototypeExporterPatch) {
patchExporterClass();
}

const batchSpanProcessor = new BatchSpanProcessor(exporter, {
...this.defaultProperties.exporter,
Expand Down
Loading

0 comments on commit 646cb7a

Please sign in to comment.