You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When observing an application that talks to a database, it's useful to know which particular database server was used. This would allow
an APM UI to show the database on a topology visualization
an operator to look at utilization metrics for the relevant host
Proposed Solution
The SQL DB semantic conventions recommend storing this information in the attribute server.address.
Alternatives
network.peer.address is another semconv attribute to consider for this purpose. Note that the DB semconv suggests in a footnote that
When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.
If we're concerned that we can't meet this high standard, network.peer.address may be a way to convey our limited knowledge.
Prior Art
In Python, the SQLAlchemy instrumentation generates network.peer.address.
In Java, I believe (but have not confirmed) that the JDBC instrumentation generates server.address.
I would consider adding server.address, as it reflects the server address behind any intermediaries.
Adding network.peer.address may create noise in the topology visualization since the path from the client to the server may not be the same as the path from the receiver (otel collector receiver) to the server. Besides, the server itself may not be aware of the intermediaries, so the telemetry data populated from the server, if any, could only include the server.address.
However, the otelsql can only make the best effort when populating server.address by parsing the DSN provided by users, which may be the proxy address instead of the server address.
To mitigate this issue, I would like to make WithAttributes overwrite attributes whatever the library automatically resolves. So, users can use WithAttributes to populate server.address as a backup to make it correct when correlating with data from other sources.
Hi @punya, I checked the automated approach, but with the current design, only the otelsql.Register, otelsql.WrapDriver, and otelsql.Open get the chance to automatically populate the server.address attributes.
otelsql.OpenDB and otelsql.RegisterDBStatsMetrics will not be able to populate the attribute automatically.
So, for the consistency of adding the server.address attribute to traces and metrics, instead of implementing an automatic attribute injecting for part of the functionality, I am thinking about adding a helper function, like AttributesFromDSN.
For instance, users can use this helper function to generate attributes from their DSN:
// Connect to databasedb, err:=otelsql.Open("mysql", mysqlDSN, otelsql.WithAttributes(
semconv.DBSystemMySQL,
otelsql.AttributesFromDSN(mysqlDSN)...,
))
iferr!=nil {
log.Fatal(err)
}
// Register DB stats to metererr=otelsql.RegisterDBStatsMetrics(db, otelsql.WithAttributes(
semconv.DBSystemMySQL,
otelsql.AttributesFromDSN(mysqlDSN)...,
))
iferr!=nil {
log.Fatal(err)
}
The automation approach (which only works for some functions) can be implemented after this helper function.
I have been thinking about the automation approach for a while, but I feel the otelsql.AttributesFromDSN(mysqlDSN) itself can be the standard way to initialize otelsql. This also prevents inconsistency (some initialization methods can automatically resolve server.address while others cannot).
So, I think the automation approach is not needed.
Closing this issue as completed. @punya, feel free to re-open it if you have any concerns.
Activity
XSAM commentedon Dec 19, 2024
Hi @punya, thanks for raising this PR.
I would consider adding
server.address, as it reflects the server address behind any intermediaries.Adding
network.peer.addressmay create noise in the topology visualization since the path from theclientto theservermay not be the same as the path from thereceiver (otel collector receiver)to theserver. Besides, the server itself may not be aware of the intermediaries, so the telemetry data populated from theserver, if any, could only include theserver.address.See, https://opentelemetry.io/docs/specs/semconv/general/attributes/#clientserver-example-with-reverse-proxy
However, the
otelsqlcan only make the best effort when populatingserver.addressby parsing the DSN provided by users, which may be the proxy address instead of the server address.To mitigate this issue, I would like to make
WithAttributesoverwrite attributes whatever the library automatically resolves. So, users can useWithAttributesto populateserver.addressas a backup to make it correct when correlating with data from other sources.WDYT?
punya commentedon Dec 19, 2024
That sounds perfect @XSAM -- so
otelsqlwould populate a default value by parsing the DSN, but allow the user to override it if necessary. Thanks!Let me know if you're planning to implement this yourself or if you're looking for a contribution.
XSAM commentedon Dec 20, 2024
That is great! I am planning to implement this myself in recent days.
XSAM commentedon Jan 30, 2025
Hi @punya, I checked the automated approach, but with the current design, only the
otelsql.Register,otelsql.WrapDriver, andotelsql.Openget the chance to automatically populate theserver.addressattributes.otelsql.OpenDBandotelsql.RegisterDBStatsMetricswill not be able to populate the attribute automatically.So, for the consistency of adding the
server.addressattribute to traces and metrics, instead of implementing an automatic attribute injecting for part of the functionality, I am thinking about adding a helper function, likeAttributesFromDSN.For instance, users can use this helper function to generate attributes from their DSN:
The automation approach (which only works for some functions) can be implemented after this helper function.
punya commentedon Jan 30, 2025
@XSAM your plan makes sense. Even before the automation approach, having the helper functions available and documented will be very useful.
Add AttributesFromDSN method (#419)
XSAM commentedon May 20, 2025
I have been thinking about the automation approach for a while, but I feel the
otelsql.AttributesFromDSN(mysqlDSN)itself can be the standard way to initialize otelsql. This also prevents inconsistency (some initialization methods can automatically resolveserver.addresswhile others cannot).So, I think the automation approach is not needed.
Closing this issue as completed. @punya, feel free to re-open it if you have any concerns.
punya commentedon May 20, 2025
@XSAM thanks, your approach makes sense.