Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sync resource with some attributes that resolve asynchronously #3460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9615a79
feat(sync-resource-detectors): initial
samimusallam Dec 1, 2022
f0c6044
feat(sync-resource-detectors): initial
samimusallam Dec 1, 2022
a2f77f6
Merge branch 'main' of https://github.com/samimusallam/opentelemetry-…
samimusallam Dec 4, 2022
6b80ab0
feat(sync-resource-detectors): updated CHANGELOG.md
samimusallam Dec 4, 2022
40957fb
feat(sync-resource-detectors): fixed lint issues
samimusallam Dec 4, 2022
7f63622
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 5, 2022
c360f8b
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 5, 2022
60f763d
feat(sync-resource-detectors): fixed failing tests
samimusallam Dec 5, 2022
8279b7c
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 5, 2022
e42a64e
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 6, 2022
2776fe3
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 7, 2022
bc926fa
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 11, 2022
876a978
Update packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts
samimusallam Dec 12, 2022
e27b6b8
feat(sync-resource-detectors): _asyncAttributesPromise merged .catch …
samimusallam Dec 19, 2022
11e4955
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 19, 2022
ab9e481
feat(sync-resource-detectors): fixed tests
samimusallam Dec 20, 2022
6c29f97
feat(sync-resource-detectors): using isPromiseLike
samimusallam Dec 20, 2022
bb89113
feat(sync-resource-detectors): documented waitForAsyncAttributes retu…
samimusallam Dec 20, 2022
cc16c50
feat(sync-resource-detectors): updated asyncAttributesPromise nullish…
samimusallam Dec 20, 2022
0ad492a
feat(sync-resource-detectors): using globalErrorHandler instead of diag
samimusallam Dec 20, 2022
5dc4d31
feat(sync-resource-detectors): removed code duplication for detect-re…
samimusallam Dec 20, 2022
3ab49fb
feat(sync-resource-detectors): fixed test
samimusallam Dec 20, 2022
721bf45
feat(sync-resource-detectors): updated README.md to use sync start()
samimusallam Dec 20, 2022
508739f
feat(sync-resource-detectors): updated test with a promise that resol…
samimusallam Dec 20, 2022
7d14a7d
feat(sync-resource-detectors): removed unnecessary attributes getter
samimusallam Dec 20, 2022
952cbf4
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 20, 2022
da7adc9
feat(sync-resource-detectors): small refactor
samimusallam Dec 20, 2022
16d223a
feat(sync-resource-detectors): removed internalConfig
samimusallam Dec 20, 2022
881645e
feat(sync-resource-detectors): updated merge() to check if promise ha…
samimusallam Dec 20, 2022
6ec14cb
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Dec 22, 2022
692ef0e
feat(sync-resource-detectors): added more tests for merge()
samimusallam Dec 22, 2022
61964a5
feat(sync-resource-detectors): fixed merge() where attribute overridi…
samimusallam Jan 3, 2023
c56bff4
feat(sync-resource-detectors): updated upgrade guidelines
samimusallam Jan 3, 2023
67e8756
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 3, 2023
04c6b2f
feat(sync-resource-detectors): fixed lint
samimusallam Jan 3, 2023
86de5b4
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 4, 2023
5baca81
feat(sync-resource-detectors): removed unnecessary await
samimusallam Jan 4, 2023
270d67e
feat(sync-resource-detectors): updated upgrade guidelines
samimusallam Jan 4, 2023
0d5b588
feat(sync-resource-detectors): updated outdated test
samimusallam Jan 4, 2023
551ed5d
feat(sync-resource-detectors): use globalErrorHandler in BatchSpanPro…
samimusallam Jan 4, 2023
c635de1
feat(sync-resource-detectors): remove unused code
samimusallam Jan 4, 2023
94bfcea
feat(sync-resource-detectors): resolve _flushOneBatch() if it fails b…
samimusallam Jan 4, 2023
e719e90
feat(sync-resource-detectors): reduced timeout to avoid test delays f…
samimusallam Jan 4, 2023
c0758b3
feat(sync-resource-detectors): removed redundant call to waitForAsync…
samimusallam Jan 5, 2023
8d82355
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 5, 2023
19817f0
feat(sync-resource-detectors): await unresolved resources in forceFlu…
samimusallam Jan 9, 2023
1af7935
feat(sync-resource-detectors): fixed test that should log detected re…
samimusallam Jan 10, 2023
76ce6f5
feat(sync-resource-detectors): fixed envDetector test
samimusallam Jan 11, 2023
cc24162
feat(sync-resource-detectors): fixed envDetector test
samimusallam Jan 11, 2023
754810d
feat(sync-resource-detectors): fixed test
samimusallam Jan 11, 2023
321f295
Update Resource's asyncAttributesHaveResolved description
samimusallam Jan 11, 2023
1c48e83
feat(sync-resource-detectors): using diag.error instead of debug
samimusallam Jan 12, 2023
85d8dbd
feat(sync-resource-detectors): removed asyncAttributesHaveResolved() …
samimusallam Jan 12, 2023
97eb9fe
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 12, 2023
8121a4d
feat(sync-resource-detectors): removed irrelevant call to shutdown()
samimusallam Jan 12, 2023
9e85a43
Update packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProc…
samimusallam Jan 12, 2023
05a83df
feat(sync-resource-detectors): updated SimpleSpanProcessor.ts
samimusallam Jan 12, 2023
ad81025
feat(sync-resource-detectors): removed redundant call
samimusallam Jan 12, 2023
ce2e87c
feat(sync-resource-detectors): updated test name
samimusallam Jan 12, 2023
8d9c4a7
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 15, 2023
e1a3795
feat(sync-resource-detectors): Added DetectorSync interface
samimusallam Jan 15, 2023
62546b0
feat(sync-resource-detectors): revert change
samimusallam Jan 15, 2023
70f47a3
feat(sync-resource-detectors): Added new interface for sync detector …
samimusallam Jan 17, 2023
9e87de6
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 17, 2023
588d93c
feat(sync-resource-detectors): Fixed issues with Detector/DetectorSync
samimusallam Jan 17, 2023
4414ba5
feat(sync-resource-detectors): removed unnecessary comments
samimusallam Jan 17, 2023
b110dca
feat(sync-resource-detectors): added test for pending resource in Bat…
samimusallam Jan 18, 2023
2365748
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 18, 2023
79a8321
Update packages/opentelemetry-resources/src/types.ts
samimusallam Jan 19, 2023
1800c53
Update packages/opentelemetry-resources/src/Resource.ts
samimusallam Jan 19, 2023
c92412f
feat(sync-resource-detectors): fixed failing tests
samimusallam Jan 19, 2023
11848b3
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 22, 2023
680f955
feat(sync-resource-detectors): deprecated Detector interface
samimusallam Jan 24, 2023
b49a1d8
feat(sync-resource-detectors): added compatibility tests and renamed …
samimusallam Jan 24, 2023
1117c1e
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 24, 2023
a9e6614
feat(sync-resource-detectors): using JSON.stringify instead of utils.…
samimusallam Jan 24, 2023
0eefbdf
feat(sync-resource-detectors): added logging test
samimusallam Jan 24, 2023
d070c0c
feat(sync-resource-detectors): updated "Upgrade guidelines"
samimusallam Jan 24, 2023
79496cd
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 25, 2023
fd850e2
feat(sync-resource-detectors): fixed regex in test
samimusallam Jan 26, 2023
964a20b
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 29, 2023
f66ebad
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 30, 2023
0c20294
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 30, 2023
96230d6
feat(sync-resource-detectors): removed typo
samimusallam Jan 30, 2023
bc8f2ba
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Jan 31, 2023
7611fa8
feat(sync-resource-detectors): created IResource interface
samimusallam Feb 2, 2023
5271cb2
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Feb 3, 2023
0ff2427
feat(sync-resource-detectors): reverted detectors to the old detector…
samimusallam Feb 5, 2023
031461e
feat(sync-resource-detectors): fixed codecov issues
samimusallam Feb 5, 2023
c2d6760
feat(sync-resource-detectors): fix typo
samimusallam Feb 5, 2023
0f1dff0
feat(sync-resource-detectors): using optional chaining
samimusallam Feb 5, 2023
f14271f
feat(sync-resource-detectors): updated README.md
samimusallam Feb 5, 2023
000adf9
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Feb 7, 2023
33eee0b
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Feb 8, 2023
7334f64
Merge branch 'main' into feat/sync-resource-detectors
dyladan Feb 8, 2023
1149d96
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Feb 9, 2023
e46852a
Merge branch 'main' into feat/sync-resource-detectors
samimusallam Feb 12, 2023
60a161a
Merge branch 'main' into feat/sync-resource-detectors
legendecas Feb 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* feat(resource): create sync resource with some attributes that resolve asynchronously [#3460](https://github.com/open-telemetry/opentelemetry-js/pull/3460) @samimusallam
* feat (api-logs): separate Events API into its own package [3550](https://github.com/open-telemetry/opentelemetry-js/pull/3550) @martinkuba
* feat(sdk-metrics): apply binary search in histogram recording [#3539](https://github.com/open-telemetry/opentelemetry-js/pull/3539) @legendecas
* perf(propagator-jaeger): improve deserializeSpanContext performance [#3541](https://github.com/open-telemetry/opentelemetry-js/pull/3541) @doochik
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ const sdk = new opentelemetry.NodeSDK({

// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start()
.then(() => console.log('Tracing initialized'))
.catch((error) => console.log('Error initializing tracing', error));
sdk.start();

// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
Expand Down Expand Up @@ -277,6 +275,11 @@ These instrumentations are hosted at <https://github.com/open-telemetry/opentele

## Upgrade guidelines

### 0.35.x to 0.36.0

- `@opentelemetry/sdk-node` changed `await start()` to now be synchronous
- `@opentelemetry/sdk-node` changed `await detectResources()` to now be synchronous

### 0.28.x to 0.29.x

- `@opentelemetry/exporter-trace-otlp-http` is now exporting `scopeSpans` instead of `instrumentationLibrarySpans`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { diag } from '@opentelemetry/api';
import {
Detector,
IResource,
Resource,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
Expand All @@ -27,7 +28,7 @@ import { BROWSER_ATTRIBUTES, UserAgentData } from './types';
* BrowserDetector will be used to detect the resources related to browser.
*/
class BrowserDetector implements Detector {
async detect(config?: ResourceDetectionConfig): Promise<Resource> {
async detect(config?: ResourceDetectionConfig): Promise<IResource> {
const isBrowser = typeof navigator !== 'undefined';
if (!isBrowser) {
return Resource.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as sinon from 'sinon';
import { Resource } from '@opentelemetry/resources';
import { IResource } from '@opentelemetry/resources';
import { browserDetector } from '../src/BrowserDetector';
import { describeBrowser, assertResource, assertEmptyResource } from './util';

Expand Down Expand Up @@ -47,7 +47,7 @@ describeBrowser('browserDetector()', () => {
},
});

const resource: Resource = await browserDetector.detect();
const resource: IResource = await browserDetector.detect();
assertResource(resource, {
platform: 'platform',
brands: ['Chromium 106', 'Google Chrome 106', 'Not;A=Brand 99'],
Expand All @@ -63,7 +63,7 @@ describeBrowser('browserDetector()', () => {
userAgentData: undefined,
});

const resource: Resource = await browserDetector.detect();
const resource: IResource = await browserDetector.detect();
assertResource(resource, {
language: 'en-US',
user_agent: 'dddd',
Expand All @@ -74,7 +74,7 @@ describeBrowser('browserDetector()', () => {
sinon.stub(globalThis, 'navigator').value({
userAgent: '',
});
const resource: Resource = await browserDetector.detect();
const resource: IResource = await browserDetector.detect();
assertEmptyResource(resource);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { Suite } from 'mocha';
import * as assert from 'assert';
import { BROWSER_ATTRIBUTES } from '../src/types';
import { Resource } from '@opentelemetry/resources';
import { IResource } from '@opentelemetry/resources';

export function describeBrowser(title: string, fn: (this: Suite) => void) {
title = `Browser: ${title}`;
Expand All @@ -27,7 +27,7 @@ export function describeBrowser(title: string, fn: (this: Suite) => void) {
}

export const assertResource = (
resource: Resource,
resource: IResource,
validations: {
platform?: string;
brands?: string[];
Expand Down Expand Up @@ -74,6 +74,6 @@ export const assertResource = (
*
* @param resource the Resource to validate
*/
export const assertEmptyResource = (resource: Resource) => {
export const assertEmptyResource = (resource: IResource) => {
assert.strictEqual(Object.keys(resource.attributes).length, 0);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
Histogram,
} from '@opentelemetry/sdk-metrics';
import { hrTimeToMilliseconds } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { IResource } from '@opentelemetry/resources';

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

protected _serializeResource(resource: Resource): string {
protected _serializeResource(resource: IResource): string {
const name = 'target_info';
const help = `# HELP ${name} Target metadata`;
const type = `# TYPE ${name} gauge`;
Expand Down
18 changes: 10 additions & 8 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import {
} from '@opentelemetry/instrumentation';
import {
Detector,
detectResources,
DetectorSync,
detectResourcesSync,
envDetector,
IResource,
processDetector,
Resource,
ResourceDetectionConfig,
Expand Down Expand Up @@ -63,8 +65,8 @@ export class NodeSDK {
private _meterProviderConfig?: MeterProviderConfig;
private _instrumentations: InstrumentationOption[];

private _resource: Resource;
private _resourceDetectors: Detector[];
private _resource: IResource;
private _resourceDetectors: Array<Detector | DetectorSync>;

private _autoDetectResources: boolean;

Expand Down Expand Up @@ -183,7 +185,7 @@ export class NodeSDK {
}

/** Detect resource attributes */
public async detectResources(): Promise<void> {
public detectResources(): void {
samimusallam marked this conversation as resolved.
Show resolved Hide resolved
if (this._disabled) {
return;
}
Expand All @@ -192,18 +194,18 @@ export class NodeSDK {
detectors: this._resourceDetectors,
};

this.addResource(await detectResources(internalConfig));
this.addResource(detectResourcesSync(internalConfig));
}

/** Manually add a resource */
public addResource(resource: Resource): void {
public addResource(resource: IResource): void {
this._resource = this._resource.merge(resource);
}

/**
* Once the SDK has been configured, call this method to construct SDK components and register them with the OpenTelemetry API.
*/
public async start(): Promise<void> {
public start(): void {
samimusallam marked this conversation as resolved.
Show resolved Hide resolved
samimusallam marked this conversation as resolved.
Show resolved Hide resolved
if (this._disabled) {
return;
}
Expand All @@ -213,7 +215,7 @@ export class NodeSDK {
});

if (this._autoDetectResources) {
await this.detectResources();
this.detectResources();
}

this._resource =
Expand Down
4 changes: 2 additions & 2 deletions experimental/packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { ContextManager, SpanAttributes } from '@opentelemetry/api';
import { TextMapPropagator } from '@opentelemetry/api';
import { InstrumentationOption } from '@opentelemetry/instrumentation';
import { Detector, Resource } from '@opentelemetry/resources';
import { Detector, DetectorSync, Resource } from '@opentelemetry/resources';
import { MetricReader, View } from '@opentelemetry/sdk-metrics';
import {
Sampler,
Expand All @@ -35,7 +35,7 @@ export interface NodeSDKConfiguration {
views: View[];
instrumentations: InstrumentationOption[];
resource: Resource;
resourceDetectors: Detector[];
resourceDetectors: Array<Detector | DetectorSync>;
sampler: Sampler;
serviceName?: string;
spanProcessor: SpanProcessor;
Expand Down
Loading