|
53 | 53 | Configuration |
54 | 54 | ------------- |
55 | 55 |
|
56 | | -SQLCOMMENTER |
57 | | -**************************************** |
58 | | -You can optionally configure SQLAlchemy instrumentation to enable sqlcommenter which enriches |
59 | | -the query with contextual information. |
| 56 | +SQLCommenter |
| 57 | +************ |
| 58 | +You can optionally enable sqlcommenter which enriches the query with contextual |
| 59 | +information. Queries made after setting up trace integration with sqlcommenter |
| 60 | +enabled will have configurable key-value pairs appended to them, e.g. |
| 61 | +``"select * from auth_users; /*traceparent=00-01234567-abcd-01*/"``. This |
| 62 | +supports context propagation between database client and server when database log |
| 63 | +records are enabled. For more information, see: |
| 64 | +
|
| 65 | +* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_ |
| 66 | +* `sqlcommenter <https://google.github.io/sqlcommenter/>`_ |
60 | 67 |
|
61 | 68 | .. code:: python |
62 | 69 |
|
63 | 70 | from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor |
64 | 71 |
|
65 | | - SQLAlchemyInstrumentor().instrument(enable_commenter=True, commenter_options={}) |
| 72 | + SQLAlchemyInstrumentor().instrument(enable_commenter=True) |
66 | 73 |
|
| 74 | +SQLCommenter with commenter_options |
| 75 | +*********************************** |
| 76 | +The key-value pairs appended to the query can be configured using |
| 77 | +``commenter_options``. When sqlcommenter is enabled, all available KVs/tags |
| 78 | +are calculated by default. ``commenter_options`` supports *opting out* |
| 79 | +of specific KVs. |
67 | 80 |
|
68 | | -For example, |
69 | | -:: |
70 | | -
|
71 | | - Invoking engine.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled |
72 | | - the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" |
73 | | -
|
74 | | -SQLCommenter Configurations |
75 | | -*************************** |
76 | | -We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword |
77 | | -
|
78 | | -db_driver = True(Default) or False |
| 81 | +.. code:: python |
79 | 82 |
|
80 | | -For example, |
81 | | -:: |
82 | | -Enabling this flag will add any underlying driver like psycopg2 /*db_driver='psycopg2'*/ |
| 83 | + from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor |
83 | 84 |
|
84 | | -db_framework = True(Default) or False |
| 85 | + # Opts into sqlcomment for SQLAlchemy trace integration. |
| 86 | + # Opts out of tags for db_driver, db_framework. |
| 87 | + SQLAlchemyInstrumentor().instrument( |
| 88 | + enable_commenter=True, |
| 89 | + commenter_options={ |
| 90 | + "db_driver": False, |
| 91 | + "db_framework": False, |
| 92 | + } |
| 93 | + ) |
85 | 94 |
|
86 | | -For example, |
87 | | -:: |
88 | | -Enabling this flag will add db_framework and it's version /*db_framework='sqlalchemy:0.41b0'*/ |
| 95 | +Available commenter_options |
| 96 | +########################### |
89 | 97 |
|
90 | | -opentelemetry_values = True(Default) or False |
| 98 | +The following sqlcomment key-values can be opted out of through ``commenter_options``: |
91 | 99 |
|
92 | | -For example, |
93 | | -:: |
94 | | -Enabling this flag will add traceparent values /*traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'*/ |
| 100 | ++---------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+ |
| 101 | +| Commenter Option | Description | Example | |
| 102 | ++===========================+===========================================================+===========================================================================+ |
| 103 | +| ``db_driver`` | Database driver name. | ``db_driver='psycopg2'`` | |
| 104 | ++---------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+ |
| 105 | +| ``db_framework`` | Database framework name with version. | ``db_framework='sqlalchemy:1.4.0'`` | |
| 106 | ++---------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+ |
| 107 | +| ``opentelemetry_values`` | OpenTelemetry context as traceparent at time of query. | ``traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'`` | |
| 108 | ++---------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+ |
95 | 109 |
|
96 | 110 | SQLComment in span attribute |
97 | 111 | **************************** |
98 | | -If sqlcommenter is enabled, you can further configure SQLAlchemy instrumentation to append sqlcomment to the `db.statement` span attribute for convenience of your platform. |
| 112 | +If sqlcommenter is enabled, you can opt into the inclusion of sqlcomment in |
| 113 | +the query span ``db.statement`` attribute for your needs. If ``commenter_options`` |
| 114 | +have been set, the span attribute comment will also be configured by this |
| 115 | +setting. |
99 | 116 |
|
100 | 117 | .. code:: python |
101 | 118 |
|
102 | 119 | from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor |
103 | 120 |
|
| 121 | + # Opts into sqlcomment for SQLAlchemy trace integration. |
| 122 | + # Opts into sqlcomment for `db.statement` span attribute. |
104 | 123 | SQLAlchemyInstrumentor().instrument( |
105 | 124 | enable_commenter=True, |
106 | 125 | commenter_options={}, |
107 | 126 | enable_attribute_commenter=True, |
108 | 127 | ) |
109 | 128 |
|
110 | | -
|
111 | | -For example, |
112 | | -:: |
113 | | -
|
114 | | - Invoking `engine.execute("select * from auth_users")` will lead to sql query "select * from auth_users" but when SQLCommenter and `attribute_commenter` is enabled |
115 | | - the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;" for both server query and `db.statement` span attribute. |
116 | | -
|
117 | | -Warning: capture of sqlcomment in ``db.statement`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information. |
| 129 | +Warning: |
| 130 | + Capture of sqlcomment in ``db.statement`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information. |
118 | 131 |
|
119 | 132 | API |
120 | 133 | --- |
|
0 commit comments