Skip to content

Commit

Permalink
Merge branch 'main' into feat/migrate-from-getenv-sdk-trace-base
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Feb 17, 2025
2 parents 5d2cc4e + cc7aa3c commit 0f331dc
Show file tree
Hide file tree
Showing 97 changed files with 1,239 additions and 919 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/survey-on-merged-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Survey on Merged PR by Non-Member

on:
pull_request_target:
types: [closed]

env:
PR_NUM: ${{ github.event.pull_request.number }}
SURVEY_URL: https://docs.google.com/forms/d/e/1FAIpQLSf2FfCsW-DimeWzdQgfl0KDzT2UEAqu69_f7F2BVPSxVae1cQ/viewform?entry.1540511742=open-telemetry/opentelemetry-js

jobs:
comment-on-pr:
name: Add survey to PR if author is not a member
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
if: github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v4
- name: Check if user is a member of the org
id: check-membership
run: |
USERNAME=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
ORG="${{ github.repository_owner }}"
STATUS=$(gh api "orgs/$ORG/members/$USERNAME" --silent && echo "true" || echo "false")
if [[ "$STATUS" == "true" ]]; then
echo "MEMBER_FOUND=true" >> $GITHUB_ENV
else
echo "MEMBER_FOUND=false" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}

- name: Add comment to PR if author is not a member
if: env.MEMBER_FOUND == 'false'
run: |
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 }}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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 @@ -94,6 +95,18 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* (user-facing): `isAttributeKey` was an internal utility function that was unintentionally exported. It has been removed without replacement.
* feat(sdk-trace-base)!: do not read environment variables from window in browsers [#5445](https://github.com/open-telemetry/opentelemetry-js/pull/5455) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore, please pass configuration options to constructors instead.
* Note: Node.js environment variable configuration continues to work as-is.
* feat(exporter-zipkin)!: do not read environment variables from window in browsers [#5465](https://github.com/open-telemetry/opentelemetry-js/pull/5465) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore, please pass configuration options to constructors instead.
* Note: Node.js environment variable configuration continues to work as-is.
* 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)
Expand All @@ -102,6 +115,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* `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
* feat(core): add `diagLogLevelFromString` utility [#5475](https://github.com/open-telemetry/opentelemetry-js/pull/5475) @pichlermarc

### :bug: (Bug Fix)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<img alt="license" src="https://img.shields.io/badge/license-Apache_2.0-green.svg?style=for-the-badge">
</a>
<br/>
<a href="https://circleci.com/gh/open-telemetry/opentelemetry-js">
<img alt="Build Status" src="https://circleci.com/gh/open-telemetry/opentelemetry-js.svg?style=shield">
<a href="https://github.com/open-telemetry/opentelemetry-js/actions">
<img alt="Build Status" src="https://github.com/open-telemetry/opentelemetry-js/actions/workflows/unit-test.yml/badge.svg?style=shield">
</a>
<img alt="Beta" src="https://img.shields.io/badge/status-beta-informational?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAA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vl/sLDXInsctFsXjqIRnO2ZO387lxmIboLDZCJ59KLFliNIgh9ipt6tLg9SihpRPDO1ia5byw7de1aCQmF5geOQtK509rzfdwxaKOIq+73AvwCC5/5fcV4vo3+3LpMdtWHh0ywsJC/ZGoCb8/9D8F/ifgLLl8S8QWfU8cAAAAASUVORK5CYII=">
</p>
Expand Down 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
8 changes: 8 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ All notable changes to experimental packages in this project will be documented
* 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(sdk-node)!: use `IMetricReader` over `MetricReader` [#5311](https://github.com/open-telemetry/opentelemetry-js/pull/5311)
* (user-facing): `NodeSDKConfiguration` now provides the more general `IMetricReader` type over `MetricReader`
* feat(sdk-logs)!: do not read environment variables from window in browsers [#5472](https://github.com/open-telemetry/opentelemetry-js/pull/5472) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore, please pass configuration options to constructors instead.
* Note: Node.js environment variable configuration continues to work as-is.

### :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
* feat(exporter-prometheus): add additional attributes option [#5317](https://github.com/open-telemetry/opentelemetry-js/pull/5317) @marius-a-mueller
* Add `withResourceConstantLabels` option to `ExporterConfig`. It can be used to define a regex pattern to choose which resource attributes will be used as static labels on the metrics. The default is to not set any static labels.

### :bug: (Bug Fix)

Expand All @@ -38,6 +44,8 @@ All notable changes to experimental packages in this project will be documented
* refactor(exporter-prometheus): remove unnecessary isNaN() check [#5377](https://github.com/open-telemetry/opentelemetry-js/pull/5377) @cjihrig
* refactor(sdk-node): move code to auto-instantiate propagators into utils [#5355](https://github.com/open-telemetry/opentelemetry-js/pull/5355) @pichlermarc
* chore: unpin `@opentelemetry/semantic-conventions` dep to allow better de-duplication in installs [#5439](https://github.com/open-telemetry/opentelemetry-js/pull/5439) @trentm
* refactor(instrumentation-http): migrate away from getEnv() [#5469](https://github.com/open-telemetry/opentelemetry-js/pull/5469) @pichlermarc
* refactor(sdk-node): migrate away from getEnv() [#5475](https://github.com/open-telemetry/opentelemetry-js/pull/5475) @pichlermarc

## 0.57.0

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 @@ -34,6 +34,7 @@ export class PrometheusExporter extends MetricReader {
endpoint: '/metrics',
prefix: '',
appendTimestamp: false,
withResourceConstantLabels: undefined,
};

private readonly _host?: string;
Expand Down Expand Up @@ -82,11 +83,15 @@ export class PrometheusExporter extends MetricReader {
typeof config.appendTimestamp === 'boolean'
? config.appendTimestamp
: PrometheusExporter.DEFAULT_OPTIONS.appendTimestamp;
const _withResourceConstantLabels =
config.withResourceConstantLabels ||
PrometheusExporter.DEFAULT_OPTIONS.withResourceConstantLabels;
// unref to prevent prometheus exporter from holding the process open on exit
this._server = createServer(this._requestHandler).unref();
this._serializer = new PrometheusSerializer(
this._prefix,
this._appendTimestamp
this._appendTimestamp,
_withResourceConstantLabels
);

this._baseUrl = `http://${this._host}:${this._port}/`;
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 @@ -171,17 +171,29 @@ const NO_REGISTERED_METRICS = '# no registered metrics';
export class PrometheusSerializer {
private _prefix: string | undefined;
private _appendTimestamp: boolean;
private _additionalAttributes: Attributes | undefined;
private _withResourceConstantLabels: RegExp | undefined;

constructor(prefix?: string, appendTimestamp = false) {
constructor(
prefix?: string,
appendTimestamp = false,
withResourceConstantLabels?: RegExp
) {
if (prefix) {
this._prefix = prefix + '_';
}
this._appendTimestamp = appendTimestamp;
this._withResourceConstantLabels = withResourceConstantLabels;
}

serialize(resourceMetrics: ResourceMetrics): string {
let str = '';

this._additionalAttributes = this._filterResourceConstantLabels(
resourceMetrics.resource.attributes,
this._withResourceConstantLabels
);

for (const scopeMetrics of resourceMetrics.scopeMetrics) {
str += this._serializeScopeMetrics(scopeMetrics);
}
Expand All @@ -193,6 +205,22 @@ export class PrometheusSerializer {
return this._serializeResource(resourceMetrics.resource) + str;
}

private _filterResourceConstantLabels(
attributes: Attributes,
pattern: RegExp | undefined
) {
if (pattern) {
const filteredAttributes: Attributes = {};
for (const [key, value] of Object.entries(attributes)) {
if (key.match(pattern)) {
filteredAttributes[key] = value;
}
}
return filteredAttributes;
}
return;
}

private _serializeScopeMetrics(scopeMetrics: ScopeMetrics) {
let str = '';
for (const metric of scopeMetrics.metrics) {
Expand Down Expand Up @@ -260,7 +288,7 @@ export class PrometheusSerializer {
attributes,
value,
this._appendTimestamp ? timestamp : undefined,
undefined
this._additionalAttributes
);
return results;
}
Expand All @@ -285,7 +313,7 @@ export class PrometheusSerializer {
attributes,
value,
this._appendTimestamp ? timestamp : undefined,
undefined
this._additionalAttributes
);
}

Expand All @@ -312,19 +340,19 @@ export class PrometheusSerializer {
attributes,
cumulativeSum,
this._appendTimestamp ? timestamp : undefined,
{
Object.assign({}, this._additionalAttributes ?? {}, {
le:
upperBound === undefined || upperBound === Infinity
? '+Inf'
: String(upperBound),
}
})
);
}

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 @@ -66,4 +66,12 @@ export interface ExporterConfig {
* @experimental
*/
metricProducers?: MetricProducer[];

/**
* Regex pattern for defining which resource attributes will be applied
* as constant labels to the metrics.
* e.g. 'telemetry_.+' for all attributes starting with 'telemetry'.
* @default undefined (no resource attributes are applied)
*/
withResourceConstantLabels?: RegExp;
}
Loading

0 comments on commit 0f331dc

Please sign in to comment.