File tree Expand file tree Collapse file tree 3 files changed +53
-2
lines changed
Expand file tree Collapse file tree 3 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 2121from opentelemetry .trace import Span , SpanContext , get_current_span
2222from opentelemetry .sdk .trace .export import BatchSpanProcessor , Span
2323from opentelemetry .sdk .trace .sampling import ALWAYS_OFF
24- from synapseclient import Synapse
24+ from synapseclient import Synapse , USER_AGENT
2525from werkzeug import Request
2626
2727from schematic .configuration .configuration import CONFIG
3535# Ensure environment variables are loaded
3636load_dotenv ()
3737
38+ USER_AGENT_LIBRARY = {
39+ "User-Agent" : USER_AGENT ["User-Agent" ] + f" schematic/{ __version__ } "
40+ }
41+
42+ USER_AGENT_COMMAND_LINE = {
43+ "User-Agent" : USER_AGENT ["User-Agent" ] + f" schematiccommandline/{ __version__ } "
44+ }
45+
46+ USER_AGENT |= USER_AGENT_LIBRARY
47+
3848
3949class AttributePropagatingSpanProcessor (SpanProcessor ):
4050 """A custom span processor that propagates specific attributes from the parent span
Original file line number Diff line number Diff line change 1414from schematic .visualization .commands import (
1515 viz as viz_cli ,
1616) # viz generation commands
17- from schematic import __version__
17+ from schematic import __version__ , USER_AGENT_COMMAND_LINE
18+
1819
1920logger = logging .getLogger ()
2021click_log .basic_config (logger )
@@ -31,6 +32,10 @@ def main():
3132 """
3233 Command line interface to the `schematic` backend services.
3334 """
35+ from synapseclient import USER_AGENT
36+
37+ USER_AGENT |= USER_AGENT_COMMAND_LINE
38+
3439 logger .info ("Starting schematic..." )
3540 logger .debug ("Existing sub-commands need to be used with schematic." )
3641
Original file line number Diff line number Diff line change 1+ from re import search
2+ from click .testing import CliRunner
3+ import pytest
4+
5+
6+ @pytest .fixture
7+ def command_line_user_agent_pattern ():
8+ yield "schematiccommandline" + "/(\\ S+)"
9+
10+
11+ @pytest .fixture
12+ def library_user_agent_pattern ():
13+ yield "schematic" + "/(\\ S+)"
14+
15+
16+ class TestUserAgentString :
17+ def test_user_agent_string (
18+ self ,
19+ library_user_agent_pattern ,
20+ command_line_user_agent_pattern ,
21+ ):
22+ # GIVEN the default USER_AGENT string from the synapse client
23+ from synapseclient import USER_AGENT
24+
25+ # WHEN schematic is imported to be used as a library
26+ from schematic .__main__ import main
27+
28+ # THEN the User-Agent string should be updated to include the schematic library client string
29+ assert search (library_user_agent_pattern , USER_AGENT ["User-Agent" ])
30+
31+ # AND when the command line is used to execute commands
32+ runner = CliRunner ()
33+ result = runner .invoke (main )
34+
35+ # THEN the User-Agent string should be updated to include the schematic command line client string
36+ assert search (command_line_user_agent_pattern , USER_AGENT ["User-Agent" ])
You can’t perform that action at this time.
0 commit comments