Skip to content

feat: add a resourceAttributes option and two default attributes - #36

Open
bengl wants to merge 1 commit into
nodejs:mainfrom
bengl:bengl/resource-attributes
Open

bengl wants to merge 1 commit into
nodejs:mainfrom
bengl:bengl/resource-attributes

Conversation

@bengl

@bengl bengl commented Nov 3, 2026

Copy link
Copy Markdown
Member

Backends group and filter spans by resource attributes such as service.version and deployment.environment.name, and microtel had no way to set them. This adds a resourceAttributes option:

microtel.init({
  resourceAttributes: {
    'service.version': '1.4.2',
    'deployment.environment.name': 'production',
  },
});

What changed. Values are strings, booleans, or finite numbers, encoded the way span attributes are. A value replaces microtel's own value for the same key, so each key appears once, and the object is copied at init. service.name, telemetry.sdk.name, and telemetry.sdk.version are refused with an error naming the option that sets them, serviceName, sdkName, or sdkVersion, so each has one place to be set. The other telemetry.sdk.* keys are refused because microtel sets them, and so are empty keys.

Number encoding. Integers export as intValue, which OTLP writes as a decimal string. Only safe integers fit that exactly, so larger ones such as 1e21 now export as doubleValue instead of a string like "1e+21" that a collector could reject. Span attributes share the encoder, so they get the same fix.

New defaults. The resource gains service.instance.id, a random UUID made once per process, as the semantic conventions suggest, and host.name from os.hostname(). Both can be replaced through resourceAttributes.

Not taken.

  • Array values and resource detectors. Neither is needed for the attributes above.
  • An environment variable such as OTEL_RESOURCE_ATTRIBUTES. All configuration goes through init().

Tests. A table in test/test-init.js covers each way the option can be wrong. A child process checks the exported resource: the defaults, with service.instance.id the same across two exports, each value type and its encoding, including false, 0, and integers past the safe range, user values replacing host.name and process.pid, one entry per key, and the copy at init.

@bengl
bengl marked this pull request as ready for review November 3, 2026 19:41
@bengl
bengl requested a review from a team November 3, 2026 19:41
Previously, the resource microtel exports held only the service name,
the SDK, and the process, and there was no way to add attributes such
as service.version, which backends group and filter by. Now init()
takes resourceAttributes, an object of string, boolean, or finite
number values, copied at init. A user value replaces microtel's value
for its key. service.name and the telemetry.sdk.* keys are refused,
since microtel sets them and the serviceName, sdkName, and sdkVersion
options change them. Empty keys are refused too.

Integers past the safe range now export as doubleValue, for span
attributes as well. As intValue, which OTLP writes as a decimal string,
a number like 1e21 came out as "1e+21".

The resource also gains two defaults: service.instance.id, a random
UUID made once per process, and host.name from os.hostname(). Both can
be replaced through resourceAttributes.

Signed-off-by: Bryan English <bryan@bryanenglish.com>
@bengl
bengl force-pushed the bengl/resource-attributes branch from 84294f2 to a7db61b Compare November 3, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants