Skip to content

Commit

Permalink
Fix merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonWeber committed Feb 14, 2025
2 parents a17f85f + 60f2ce9 commit ef8d84e
Show file tree
Hide file tree
Showing 81 changed files with 733 additions and 781 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/survey-on-merged-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- name: Add comment to PR if author is not a member
if: env.MEMBER_FOUND == 'false'
run: |
gh pr comment ${PR_NUM} --repo open-telemetry/opentelemetry.io --body "Thank you for your contribution @${USERNAME}! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this [survey](${SURVEY_URL})."
USERNAME=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
gh pr comment ${PR_NUM} --repo open-telemetry/opentelemetry-js --body "Thank you for your contribution @${USERNAME}! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this [survey](${SURVEY_URL})."
env:
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* chore!: Raise the minimum supported Node.js version to `^18.19.0 || >=20.6.0`. Support for Node.js 14, 16, and early minor versions of 18 and 20 have been dropped. This applies to all packages except the 'api' and 'semantic-conventions' packages. [#5395](https://github.com/open-telemetry/opentelemetry-js/issues/5395) @trentm
* feat(core)!: remove TracesSamplerValues from exports [#5406](https://github.com/open-telemetry/opentelemetry-js/pull/5406) @pichlermarc
* (user-facing): TracesSamplerValues was only consumed internally and has been removed from exports without replacement
* chore(resources)!: Remove deprecated duplicate browser detector from `@opentelemetry/resource` in favor of `@opentelemetry/opentelemetry-browser-detector` [#5420](https://github.com/open-telemetry/opentelemetry-js/pull/5420)
* feat(core)!: remove unused and obsolete functions and types [#5444](https://github.com/open-telemetry/opentelemetry-js/pull/5444) @pichlermarc
* (user-facing): `VERSION` was an internal constant that was unintentionally exported. It has been removed without replacement.
* (user-facing): `isWrapped` has been removed in favor of `isWrapped` from `@opentelemetry/instrumentation`
Expand All @@ -93,13 +94,23 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* (user-facing): `baggageUtils.parsePairKeyValue` was an internal utility function that was unintentionally exported. It has been removed without replacement.
* (user-facing): `TimeOriginLegacy` has been removed without replacement.
* (user-facing): `isAttributeKey` was an internal utility function that was unintentionally exported. It has been removed without replacement.
* feat(resource)!: Remove resource class export in favor of functions and types only to aid in cross-version compatibility [#5421](https://github.com/open-telemetry/opentelemetry-js/pull/5421)
* Renames `Resource` class to `ResourceImpl` and makes it package-private
* Renames `IResource` interface to `Resource`
* Export function `resourceFromAttributes` to create a `Resource` from a `DetectedAttributes` object
* Only export types and functions. This aids in cross-version compatibility and makes it more easily extensible in the future.
* feat(resources)!: do not read environment variables from window in browsers [#5466](https://github.com/open-telemetry/opentelemetry-js/pull/5466) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore
* If you have been using the `envDetector` in browser environments, please migrate to manually creating a resource.
* Note: Node.js environment variable configuration continues to work as-is.

### :rocket: (Enhancement)

* feat(sdk-trace-web): do not throw when passing extra options [#5357](https://github.com/open-telemetry/opentelemetry-js/pull/5357) @pichlermarc
* `WebTracerProvider` constructor now does not throw anymore when `contextManager` or `propagator` are passed as extra options to the constructor
* feat(sdk-trace-base): add stack trace warning to debug instrumentation [#5363](https://github.com/open-telemetry/opentelemetry-js/pull/5363) @neilfordyce
* feat(core): add more scalable replacements for getEnv(), getEnvWithoutDefaults() [#5443](https://github.com/open-telemetry/opentelemetry-js/pull/5443) @pichlermarc
* refactor(exporter-jaeger): migrate away from getEnv() [#5464](https://github.com/open-telemetry/opentelemetry-js/pull/5464) @pichlermarc

### :bug: (Bug Fix)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ const process = require('process');
const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');

// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
const traceExporter = new ConsoleSpanExporter();
const sdk = new opentelemetry.NodeSDK({
resource: new Resource({
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'my-service',
}),
traceExporter,
Expand Down
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(instrumentation-fetch): add a `requestHook` option [#5380](https://github.com/open-telemetry/opentelemetry-js/pull/5380)
* feat(instrumentation): re-export initialize function from import-in-the-middle [#5123](https://github.com/open-telemetry/opentelemetry-js/pull/5123)
* feat(sdk-node): lower diagnostic level [#5360](https://github.com/open-telemetry/opentelemetry-js/pull/5360) @cjihrig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ npm install --save @opentelemetry/opentelemetry-browser-detector
## Usage

```js
import { Resource, detectResources } from '@opentelemetry/resources';
import { resourceFromAttributes, detectResources } from '@opentelemetry/resources';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector';

async function start(){
let resource= new Resource({
let resource = resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'Test App Name',
});
let detectedResources= await detectResources({detectors:[browserDetector]});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { Attributes, diag } from '@opentelemetry/api';
import {
DetectedResource,
ResourceDetector,
Resource,
ResourceDetectionConfig,
EMPTY_RESOURCE,
} from '@opentelemetry/resources';
import { BROWSER_ATTRIBUTES, UserAgentData } from './types';

Expand All @@ -30,7 +30,7 @@ class BrowserDetector implements ResourceDetector {
detect(config?: ResourceDetectionConfig): DetectedResource {
const isBrowser = typeof navigator !== 'undefined';
if (!isBrowser) {
return Resource.EMPTY;
return EMPTY_RESOURCE;
}
const browserResource: Attributes = getBrowserAttributes();
return this._getResourceAttributes(browserResource, config);
Expand All @@ -53,7 +53,7 @@ class BrowserDetector implements ResourceDetector {
diag.debug(
'BrowserDetector failed: Unable to find required browser resources. '
);
return Resource.EMPTY;
return EMPTY_RESOURCE;
} else {
return { attributes: browserResource };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
Histogram,
} from '@opentelemetry/sdk-metrics';
import { hrTimeToMilliseconds } from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { Resource } from '@opentelemetry/resources';

type PrometheusDataTypeLiteral =
| 'counter'
Expand Down Expand Up @@ -324,7 +324,7 @@ export class PrometheusSerializer {
return results;
}

protected _serializeResource(resource: IResource): string {
protected _serializeResource(resource: Resource): string {
const name = 'target_info';
const help = `# HELP ${name} Target metadata`;
const type = `# TYPE ${name} gauge`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
sdkVersion,
serviceName,
} from './util';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { AggregationType } from '@opentelemetry/sdk-metrics';

const attributes = {
Expand Down Expand Up @@ -703,14 +703,12 @@ describe('PrometheusSerializer', () => {
it('should serialize resource', () => {
const serializer = new PrometheusSerializer(undefined, true);
const result = serializer['_serializeResource'](
new Resource({
attributes: {
env: 'prod',
hostname: 'myhost',
datacenter: 'sdc',
region: 'europe',
owner: 'frontend',
},
resourceFromAttributes({
env: 'prod',
hostname: 'myhost',
datacenter: 'sdc',
region: 'europe',
owner: 'frontend',
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as sinon from 'sinon';
import { Resource } from '@opentelemetry/resources';
import { DEFAULT_RESOURCE } from '@opentelemetry/resources';
import {
SEMRESATTRS_SERVICE_NAME,
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,
Expand All @@ -29,19 +29,23 @@ export function mockHrTime() {
sinon.useFakeTimers(mockedHrTimeMs);
}

export const serviceName = Resource.default()
.attributes[SEMRESATTRS_SERVICE_NAME]?.toString()
export const serviceName = DEFAULT_RESOURCE.attributes[
SEMRESATTRS_SERVICE_NAME
]?.toString()
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n');
export const sdkLanguage = Resource.default()
.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]?.toString()
export const sdkLanguage = DEFAULT_RESOURCE.attributes[
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE
]?.toString()
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n');
export const sdkName = Resource.default()
.attributes[SEMRESATTRS_TELEMETRY_SDK_NAME]?.toString()
export const sdkName = DEFAULT_RESOURCE.attributes[
SEMRESATTRS_TELEMETRY_SDK_NAME
]?.toString()
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n');
export const sdkVersion = Resource.default()
.attributes[SEMRESATTRS_TELEMETRY_SDK_VERSION]?.toString()
export const sdkVersion = DEFAULT_RESOURCE.attributes[
SEMRESATTRS_TELEMETRY_SDK_VERSION
]?.toString()
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n');
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ See [examples/tracer-web/fetch](https://github.com/open-telemetry/opentelemetry-

Fetch instrumentation plugin has few options available to choose from. You can set the following:

| Options | Type | Description |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|-----------------------------------------------------------------------------------------|
| [`applyCustomAttributesOnSpan`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L75) | `HttpCustomAttributeFunction` | Function for adding custom attributes |
| [`ignoreNetworkEvents`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L77) | `boolean` | Disable network events being added as span events (network events are added by default) |
| [`measureRequestSize`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L79) | `boolean` | Measure outgoing request length (outgoing request length is not measured by default) |
| Options | Type | Description |
| ------- | ---- | ----------- |
| [`applyCustomAttributesOnSpan`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L83) | `FetchCustomAttributeFunction` | Function for adding custom attributes |
| [`requestHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L85) | `FetchRequestHookFunction` | Function for adding custom attributes or headers before the request is handled |
| [`ignoreNetworkEvents`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L87) | `boolean`| Disable network events being added as span events (network events are added by default) |
| [`measureRequestSize`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L89) | `boolean` | Measure outgoing request length (outgoing request length is not measured by default) |

## Semantic Conventions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export interface FetchCustomAttributeFunction {
): void;
}

export interface FetchRequestHookFunction {
(span: api.Span, request: Request | RequestInit): void;
}

/**
* FetchPlugin Config
*/
Expand All @@ -74,6 +78,8 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
ignoreUrls?: Array<string | RegExp>;
/** Function for adding custom attributes on the span */
applyCustomAttributesOnSpan?: FetchCustomAttributeFunction;
/** Function for adding custom attributes or headers before the request is handled */
requestHook?: FetchRequestHookFunction;
// Ignore adding network events as span events
ignoreNetworkEvents?: boolean;
/** Measure outgoing request size */
Expand Down Expand Up @@ -416,6 +422,8 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
api.trace.setSpan(api.context.active(), createdSpan),
() => {
plugin._addHeaders(options, url);
// Important to execute "_callRequestHook" after "_addHeaders", allowing the consumer code to override the request headers.
plugin._callRequestHook(createdSpan, options);
plugin._tasksCount++;
// TypeScript complains about arrow function captured a this typed as globalThis
// ts(7041)
Expand Down Expand Up @@ -457,6 +465,23 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
}
}

private _callRequestHook(span: api.Span, request: Request | RequestInit) {
const requestHook = this.getConfig().requestHook;
if (requestHook) {
safeExecuteInTheMiddle(
() => requestHook(span, request),
error => {
if (!error) {
return;
}

this._diag.error('requestHook', error);
},
true
);
}
}

/**
* Prepares a span data - needed later for matching appropriate network
* resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export {
FetchCustomAttributeFunction,
FetchRequestHookFunction,
FetchInstrumentation,
FetchInstrumentationConfig,
} from './fetch';
Loading

0 comments on commit ef8d84e

Please sign in to comment.