Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
d794584f
Commit
d794584f
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added `tags_factory` to `trace_function`
parent
bdae5fa5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/opentracing/trace.py
+23
-3
23 additions, 3 deletions
satella/opentracing/trace.py
with
26 additions
and
4 deletions
CHANGELOG.md
+
2
−
0
View file @
d794584f
# v2.12.3
# v2.12.3
*
added
`tags_factory`
to
`trace_function`
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
d794584f
__version__
=
'
2.12.3
_a1
'
__version__
=
'
2.12.3
'
This diff is collapsed.
Click to expand it.
satella/opentracing/trace.py
+
23
−
3
View file @
d794584f
import
copy
import
typing
as
tp
import
typing
as
tp
import
sys
import
sys
import
warnings
import
warnings
...
@@ -14,19 +15,38 @@ except ImportError:
...
@@ -14,19 +15,38 @@ except ImportError:
pass
pass
def
trace_function
(
tracer
,
name
:
str
,
tags
:
tp
.
Optional
[
dict
]
=
None
):
def
trace_function
(
tracer
,
name
:
str
,
tags
:
tp
.
Optional
[
dict
]
=
None
,
tags_factory
:
tp
.
Optional
[
tp
.
List
[
tp
.
Tuple
[
str
,
tp
.
Callable
]]]
=
None
):
"""
"""
Return a decorator that will trace the execution of a given function
Return a decorator that will trace the execution of a given function
using tracer.start_active_span
using tracer.start_active_span.
Can optionally construct it
'
s tags from a predicate building, example:
>>>
class
Device
:
>>>
device_id
=
'
test
'
>>>
@trace_function
(
tracer
,
'
Processing
'
,
tags_factory
=
[(
'
device_id
'
,
x
[
0
].
device_id
)])
>>>
def
process
(
device
:
Device
):
>>>
...
:param tracer: tracer to use
:param tracer: tracer to use
:param name: Name of the trace
:param name: Name of the trace
:param tags: optional tags to use
:param tags: optional tags to use
:param tags_factory: a list of tuple (tag name, callable that is called with *args passed to
this function as a sole argument). Extra tags will be generated from this.
"""
"""
def
outer
(
fun
):
def
outer
(
fun
):
@wraps
(
fun
)
@wraps
(
fun
)
def
inner
(
*
args
,
**
kwargs
):
def
inner
(
*
args
,
**
kwargs
):
with
tracer
.
start_active_span
(
name
,
tags
=
tags
):
nonlocal
tags
,
tags_factory
my_tags
=
tags
if
tags_factory
is
not
None
:
if
tags
is
None
:
tags
=
{}
my_tags
=
copy
.
copy
(
tags
)
for
key
,
value
in
tags_factory
:
my_tags
[
key
]
=
value
(
args
)
with
tracer
.
start_active_span
(
name
,
tags
=
my_tags
):
return
fun
(
*
args
,
**
kwargs
)
return
fun
(
*
args
,
**
kwargs
)
return
inner
return
inner
return
outer
return
outer
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment