Skip to content

feat: Adding trace context in sql query as the comments #479

@xuan-cao-swi

Description

@xuan-cao-swi

When executing sql through ORM (e.g. active_record and sequel), I'd like to inject some comments (e.g. trace context) into sql query before hitting the sql database server.

The most important comment is the traceparent that is consisted of trace context information (i.e. 00-%<trace_id>s-%<span_id>s-%<trace_flags>.2d), which is for trace correlation.

# uninjected query
SELECT "posts".* FROM "posts"

# injected query
SELECT "posts".* FROM "posts" /*action='index',application='SqlcommenterRailsDemo',controller='posts',db_driver='ActiveRecord::ConnectionAdapters::SQLite3Adapter',framework='rails_v6.0.0.rc1',route='/posts',traceparent='00-828f28f7fb3df3dd07ee6478b2016b2a-a52cad0a8d1425ab-01'*/ 

# example from https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo#get-posts

Marginalia and sqlcommenter should handle the case if both marginalia and sqlcommenter is required from end user.

Will opentelemetry-ruby integrate the marginalia and sqlcommenter into the codebase in the future so that end user doesn't need to require in their side (as automatic as possible)?

I created the pr for opentelemtery integration with marginalia here (i.e. extension of marginalia).

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestkeepEnsures stale-bot keeps this issue/PR open

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions