Skip to content

Commit

Permalink
feat: add server.address tags to db client integrations (#10123)
Browse files Browse the repository at this point in the history
This is the second part of work to add `server.address` tags to
integrations.

Follow up to #10064 .

Integrations modified:
- psycopg
- pylibmc
- redis
     - note: yaaredis is about to be deprecated
- urllib3

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
quinna-h committed Aug 13, 2024
1 parent d22c6c1 commit 7112beb
Show file tree
Hide file tree
Showing 69 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddtrace/contrib/psycopg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def patch_conn(conn, traced_conn_cls, pin=None):
tags = {
net.TARGET_HOST: dsn.get("host"),
net.TARGET_PORT: dsn.get("port", 5432),
net.SERVER_ADDRESS: dsn.get("host"),
db.NAME: dsn.get("dbname"),
db.USER: dsn.get("user"),
"db.application": dsn.get("application_name"),
Expand Down
1 change: 1 addition & 0 deletions ddtrace/contrib/psycopg/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, *args, **kwargs):
self._datadog_tags = {
net.TARGET_HOST: dsn.get("host"),
net.TARGET_PORT: dsn.get("port"),
net.SERVER_ADDRESS: dsn.get("host"),
db.NAME: dsn.get("dbname"),
db.USER: dsn.get("user"),
db.SYSTEM: config.psycopg.dbms_name,
Expand Down
1 change: 1 addition & 0 deletions ddtrace/contrib/pylibmc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def _tag_span(self, span):
_, host, port, _ = random.choice(self._addresses) # nosec
span.set_tag_str(net.TARGET_HOST, host)
span.set_tag(net.TARGET_PORT, port)
span.set_tag_str(net.SERVER_ADDRESS, host)

# set analytics sample rate
span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.pylibmc.get_analytics_sample_rate())
1 change: 1 addition & 0 deletions ddtrace/contrib/redis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _extract_conn_tags(conn_kwargs):
conn_tags = {
net.TARGET_HOST: conn_kwargs["host"],
net.TARGET_PORT: conn_kwargs["port"],
net.SERVER_ADDRESS: conn_kwargs["host"],
redisx.DB: conn_kwargs.get("db") or 0,
}
client_name = conn_kwargs.get("client_name")
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/contrib/urllib3/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ...constants import SPAN_KIND
from ...ext import SpanKind
from ...ext import SpanTypes
from ...ext import net
from ...internal.compat import parse
from ...internal.schema import schematize_service_name
from ...internal.schema import schematize_url_operation
Expand Down Expand Up @@ -158,5 +159,6 @@ def _wrap_urlopen(func, instance, args, kwargs):
response_headers={} if response is None else dict(response.headers),
retries_remain=retries,
)
span.set_tag_str(net.SERVER_ADDRESS, instance.host)

return response
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
database_clients: Adds ``server.address`` tag to all ``<database>.query`` spans (ex: postgres.query). This tag stores the name of the database host.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET here...",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "GET put_key_in_resource",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -66,6 +67,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "SET pipeline-cmd1 1\nSET pipeline-cmd2 2",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "GET put_key_in_resource",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -66,6 +67,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "SET pipeline-cmd1 1\nSET pipeline-cmd2 2",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "MGET 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 36...",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "SET a 1",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -53,6 +54,7 @@
"out.host": "localhost",
"redis.raw_command": "SET a 1",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "SET blah 32\nRPUSH foo \u00e9\u00e9\nHGETALL xxx",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET \ud83d\ude10",
"runtime-id": "2bc441c84b6b45fc9d6f6fdef59a24f3",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "91b9e07942704e02bd33721f33785cc6",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -58,6 +59,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client",
"sql.executemany": "true"
},
Expand Down Expand Up @@ -96,6 +98,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -133,6 +136,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client",
"sql.executemany": "true"
},
Expand Down Expand Up @@ -171,6 +175,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -208,6 +213,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "8f3f46668bbc48e5be37411599b3ba6d",
"server.address": "127.0.0.1",
"span.kind": "client",
"sql.executemany": "true"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "5e80c5a691c84329bbe0464d28854fae",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "4b04b30d8b3e43eab009a6e5a167f3c1",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -58,6 +59,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "4b04b30d8b3e43eab009a6e5a167f3c1",
"server.address": "127.0.0.1",
"span.kind": "client",
"sql.executemany": "true"
},
Expand Down Expand Up @@ -96,6 +98,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "4b04b30d8b3e43eab009a6e5a167f3c1",
"server.address": "127.0.0.1",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -133,6 +136,7 @@
"language": "python",
"out.host": "127.0.0.1",
"runtime-id": "4b04b30d8b3e43eab009a6e5a167f3c1",
"server.address": "127.0.0.1",
"span.kind": "client",
"sql.executemany": "true"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET here...",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET here-is...",
"runtime-id": "ea409d0295db44adbf88dda3e4806547",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "e263ff9ad1cd43099216a11ca5e19377",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -54,6 +55,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "e263ff9ad1cd43099216a11ca5e19377",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"out.host": "localhost",
"redis.raw_command": "GET put_key_in_resource",
"runtime-id": "3a1f7ba9b1ab42f4858e5effd03877ef",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -52,6 +53,7 @@
"out.host": "localhost",
"redis.raw_command": "SET pipeline-cmd1 1\nSET pipeline-cmd2 2",
"runtime-id": "3a1f7ba9b1ab42f4858e5effd03877ef",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"out.host": "localhost",
"redis.raw_command": "GET put_key_in_resource",
"runtime-id": "451464ac55804a488cf355b1d96c7002",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -52,6 +53,7 @@
"out.host": "localhost",
"redis.raw_command": "SET pipeline-cmd1 1\nSET pipeline-cmd2 2",
"runtime-id": "451464ac55804a488cf355b1d96c7002",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "MGET 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 36...",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"db.system": "redis",
"out.host": "localhost",
"redis.raw_command": "GET cheese",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "SET a 1",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down Expand Up @@ -53,6 +54,7 @@
"out.host": "localhost",
"redis.raw_command": "SET a 1",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"out.host": "localhost",
"redis.raw_command": "SET blah 32\nRPUSH foo \u00e9\u00e9\nHGETALL xxx",
"runtime-id": "3cf1df7fb079462ab81608355e026651",
"server.address": "localhost",
"span.kind": "client"
},
"metrics": {
Expand Down
Loading

0 comments on commit 7112beb

Please sign in to comment.