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

fix(sdk-logs): ensure default resource attributes are used as fallbacks when a resource is passed to LoggerProvider #4564

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to experimental packages in this project will be documented

* fix(exporter-*-otlp-*): use parseHeaders() to ensure header-values are not 'undefined' #4540
* Fixes a bug where passing `undefined` as a header value would crash the end-user app after the export timeout elapsed.
* fix(sdk-logs): ensure default resource attributes are used as fallbacks when a resource is passed to LoggerProvider.

### :books: (Refine Doc)

Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/sdk-logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const logger = logsAPI.logs.getLogger('default');

// emit a log record
logger.emit({
severityNumber: SeverityNumber.INFO,
severityNumber: logsAPI.SeverityNumber.INFO,
severityText: 'INFO',
body: 'this is a log record body',
attributes: { 'log.type': 'LogRecord' },
Expand Down
13 changes: 6 additions & 7 deletions experimental/packages/sdk-logs/src/LoggerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ export class LoggerProvider implements logsAPI.LoggerProvider {
private readonly _sharedState: LoggerProviderSharedState;

constructor(config: LoggerProviderConfig = {}) {
const {
resource = Resource.default(),
logRecordLimits,
forceFlushTimeoutMillis,
} = merge({}, loadDefaultConfig(), config);
const mergedConfig = merge({}, loadDefaultConfig(), config);
const resource = Resource.default().merge(
mergedConfig.resource ?? Resource.empty()
);
this._sharedState = new LoggerProviderSharedState(
resource,
forceFlushTimeoutMillis,
reconfigureLimits(logRecordLimits)
mergedConfig.forceFlushTimeoutMillis,
reconfigureLimits(mergedConfig.logRecordLimits)
);
this._shutdownOnce = new BindOnceFuture(this._shutdown, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ describe('LoggerProvider', () => {
assert.deepStrictEqual(resource, Resource.default());
});

it('should fallback to default resource attrs', () => {
const passedInResource = new Resource({ foo: 'bar' });
const provider = new LoggerProvider({ resource: passedInResource });
const { resource } = provider['_sharedState'];
assert.deepStrictEqual(
resource,
Resource.default().merge(passedInResource)
);
});

it('should have default forceFlushTimeoutMillis if not pass', () => {
const provider = new LoggerProvider();
const sharedState = provider['_sharedState'];
Expand Down