Skip to content

Commit

Permalink
Merge pull request #4 from snapADDY/fix/parent-trace-ids
Browse files Browse the repository at this point in the history
Parent trace IDs
  • Loading branch information
benedikt-budig authored Jul 13, 2022
2 parents d5de7aa + eeb0e4c commit 09efebf
Show file tree
Hide file tree
Showing 4 changed files with 473 additions and 171 deletions.
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
stages: [commit]
- id: mixed-line-ending
- id: trailing-whitespace
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
args: [--settings-path=pyproject.toml]

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
args: [--config=pyproject.toml]

- repo: https://github.com/hadialqattan/pycln
rev: v1.3.5
hooks:
- id: pycln
args: [--config=pyproject.toml]
8 changes: 6 additions & 2 deletions elastic_apm_falcon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import elasticapm
from falcon import HTTP_INTERNAL_SERVER_ERROR, Request, Response, __version__ as falcon_version
from elasticapm.utils.disttracing import TraceParent
from falcon import HTTP_INTERNAL_SERVER_ERROR, Request, Response
from falcon import __version__ as falcon_version

from elastic_apm_falcon.utils import get_data_from_request, get_data_from_response

Expand All @@ -18,8 +20,10 @@ def __init__(self, **config):

def process_request(self, req: Request, resp: Response):
if not self.client.should_ignore_url(req.path):
trace_parent = TraceParent.from_headers(req.headers)

# begin APM transaction
self.client.begin_transaction("request")
self.client.begin_transaction("request", trace_parent=trace_parent)

# provide request data as callable (so it is only called if the request is sampled)
elasticapm.set_context(lambda: get_data_from_request(req), "request")
Expand Down
Loading

0 comments on commit 09efebf

Please sign in to comment.