Skip to content

[receiver/oracledb] Add service.instance.id resource attribute to metrics and logs#42421

Merged
atoulme merged 103 commits into
open-telemetry:mainfrom
sv-splunk:main
Sep 30, 2025
Merged

[receiver/oracledb] Add service.instance.id resource attribute to metrics and logs#42421
atoulme merged 103 commits into
open-telemetry:mainfrom
sv-splunk:main

Conversation

@sv-splunk

@sv-splunk sv-splunk commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

Description

The service.instance.id attribute is added into resourceAttributes of metrics and logs to uniquely identify
Oracle db hosts. The format of id is <host>:<port>/<service>

Link to tracking issue

Fixes #42402

Testing

Unit tests are added/updated

Documentation

Comment thread receiver/oracledbreceiver/scraper.go Outdated
Comment on lines +843 to +853
if err == nil && (strings.EqualFold(host, "localhost") || net.ParseIP(host).IsLoopback()) {
host, err = os.Hostname()
}

if err != nil {
logger.Warn("Failed to compute service.instance.id", zap.Error(err))
if port == "" {
return fallback
}
return "unknown:" + port
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer handle the err != nil first.

Something like

host, port, err := net.SplitHostPort(hostString)
if err != nil {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XSAM updated!

# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The `service.instance.id` attribute is added in the format `<host>:<port>/<service>` to uniquely identify

@XSAM XSAM Sep 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the service.instance.id should not include the service. And this service has already been pushed as oracledb.instance.name. Could you elaborate on the reason for including service in the service.instance.id?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A sample Oracle connection string would be oracle://system:password123@127.0.0.1:1521/XEPDB1

In the above string the XEPDB1 is a PDB (Pluggable database) instance.

In Oracle Enterprise Edition users can spin up upto ~250 PDB instances, and they all will live under the same host and port.

This makes it necessary to have the PDB name be attached to the service.instace.id that we create.

@XSAM

Comment thread receiver/oracledbreceiver/metadata.yaml Outdated
Comment thread receiver/oracledbreceiver/scraper.go Outdated
Comment thread receiver/oracledbreceiver/scraper_test.go
Comment thread receiver/oracledbreceiver/scraper.go Outdated
Comment thread receiver/oracledbreceiver/scraper.go Outdated
if strings.EqualFold(host, "localhost") || net.ParseIP(host).IsLoopback() {
host, err = os.Hostname()
}
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this if should be next to the statement that potentially sets err. It's harder to follow when they're separated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code updated!

Comment thread receiver/oracledbreceiver/scraper.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm following the logic properly, service.instance.id will never be empty. Can we update test data to match functionality? (Same comment for expectedSamplesFile.yaml)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing empty values here, perhaps a commit wasn't pushed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think so. Updated now!

Comment thread receiver/oracledbreceiver/scraper.go Outdated

@crobert-1 crobert-1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few more nits and requests 👍

Comment thread .chloggen/service_instance_id_for_oracledbreceiver.yaml Outdated
Comment thread .chloggen/service_instance_id_for_oracledbreceiver.yaml Outdated
Comment thread .chloggen/service_instance_id_for_oracledbreceiver.yaml Outdated
Comment thread receiver/oracledbreceiver/scraper.go Outdated
Comment thread receiver/oracledbreceiver/scraper.go Outdated
Comment thread receiver/oracledbreceiver/scraper.go
Comment thread receiver/oracledbreceiver/scraper.go Outdated
return constructInstanceID(host, port, service)
}

func constructInstanceID(host, port, service string) (id string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method assumes valid host and port, should it have some validation involved? As I pointed out there was a case where host may be empty, it'd probably be good if we set defaults if empty or invalid strings were passed in, then construct the instance ID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified the method to set defaults for host and port.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing empty values here, perhaps a commit wasn't pushed?

@sv-splunk

Copy link
Copy Markdown
Contributor Author

@crobert-1 Comments addressed, please check. thanks

@atoulme atoulme merged commit 2523b1d into open-telemetry:main Sep 30, 2025
186 checks passed
@github-actions github-actions Bot added this to the next release milestone Sep 30, 2025
@otelbot

otelbot Bot commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution @sv-splunk! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[receiver/oracle] Add service.instance.id resource attribute to metrics and logs

4 participants