Skip to content

Commit

Permalink
squash: add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Nov 23, 2024
1 parent ca87a68 commit c4b1c52
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion helpers/sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ Or, if you use [bundler][bundler-home], include `opentelemetry-helpers-sql` in y

## Usage

## Examples
This gem is intended to be used by the instrumentation libraries to provide a common set of helpers for SQL-related spans. It is not intended to be used directly by applications.

Some Database libraries do not have enough context to add sufficient details to client spans. In these cases, you can use the `OpenTelemetry::Helpers::Sql.with_attributes` to create a set of shared attributes to amend to a database span.

```ruby
# Higher-level instrumentation e.g. ORM
OpenTelemetry::Helpers::Sql.with_attributes({ 'code.namespace' => 'Acme::Customer', 'code.function' => 'truncate!', 'db.operation.name' => 'TRUNCATE', 'db.namespace' => 'customers' }) do
client.query('TRUNCATE customers')
end

# Client snippet
class OtherSqlClient
def query(sql)
tracer.in_span("query", attributes: OpenTelemetry::Helpers::Sql.attributes.merge('db.statement' => sql, 'db.system' => 'other_sql')) do
connection.query(sql)
end
end
end
```

## How can I get involved?

Expand Down

0 comments on commit c4b1c52

Please sign in to comment.