66
77use Sentry \State \HubInterface ;
88use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
9+ use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
910use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
1011use Symfony \Component \Config \Definition \ConfigurationInterface ;
1112
1617class Configuration implements ConfigurationInterface
1718{
1819 public const TRACEMODE_TRACECONTEXT = 'tracecontext ' ;
19- public const TRACEMODE_TRACEID = 'traceid ' ;
20+ public const TRACEMODE_TRACEID = 'traceid ' ;
2021
2122 public function getConfigTreeBuilder (): TreeBuilder
2223 {
@@ -69,7 +70,21 @@ public function getConfigTreeBuilder(): TreeBuilder
6970 ->end ()
7071 ->booleanNode ('enable_console ' )
7172 ->info ('Whether to add the trace id to console commands, defaults to true ' )
72- ->defaultTrue ()
73+ ->defaultNull ()
74+ ->setDeprecated ('digitalrevolution/symfony-trace-bundle ' , '0.6.0 ' )
75+ ->end ()
76+ ->arrayNode ('console ' )
77+ ->addDefaultsIfNotSet ()
78+ ->children ()
79+ ->booleanNode ('enabled ' )
80+ ->info ('Whether to add the trace id to console commands, defaults to true ' )
81+ ->defaultTrue ()
82+ ->end ()
83+ ->scalarNode ('trace_id ' )
84+ ->info ('Option to set the `Trace-Id` to use for console commands from env var. Defaults to null. ' )
85+ ->defaultNull ()
86+ ->end ()
87+ ->end ()
7388 ->end ()
7489 ->booleanNode ('enable_messenger ' )
7590 ->info ('Whether to add the trace id to message bus events, defaults to false ' )
@@ -79,37 +94,53 @@ public function getConfigTreeBuilder(): TreeBuilder
7994 ->info ('Whether or not to enable the twig `trace_id()` and `transaction_id()` functions. Only works if TwigBundle is present. ' )
8095 ->defaultTrue ()
8196 ->end ()
82- ->arrayNode ('http_client ' )
83- ->addDefaultsIfNotSet ()
84- ->children ()
85- ->booleanNode ('enabled ' )
86- ->info ('Whether or not to enable the trace id aware http client ' )
87- ->defaultTrue ()
88- ->end ()
89- ->booleanNode ('tag_default_client ' )
90- ->info ('Whether or not to tag the default http client ' )
91- ->defaultFalse ()
92- ->end ()
93- ->scalarNode ('header ' )
94- ->info ('The header the bundle set in the request in the http client ' )
95- ->defaultValue ('X-Trace-Id ' )
96- ->end ()
97+ ->append ($ this ->createHttpClientConfiguration ())
98+ ->append ($ this ->createSentryConfiguration ())
99+ ;
100+
101+ return $ tree ;
102+ }
103+
104+ private function createHttpClientConfiguration (): NodeDefinition
105+ {
106+ $ node = (new TreeBuilder ('http_client ' ))->getRootNode ();
107+ $ node
108+ ->addDefaultsIfNotSet ()
109+ ->children ()
110+ ->booleanNode ('enabled ' )
111+ ->info ('Whether or not to enable the trace id aware http client ' )
112+ ->defaultTrue ()
113+ ->end ()
114+ ->booleanNode ('tag_default_client ' )
115+ ->info ('Whether or not to tag the default http client ' )
116+ ->defaultFalse ()
117+ ->end ()
118+ ->scalarNode ('header ' )
119+ ->info ('The header the bundle set in the request in the http client ' )
120+ ->defaultValue ('X-Trace-Id ' )
97121 ->end ()
98122 ->end ()
99- ->arrayNode ('sentry ' )
100- ->addDefaultsIfNotSet ()
101- ->children ()
102- ->booleanNode ('enabled ' )
123+ ->end ();
124+
125+ return $ node ;
126+ }
127+
128+ private function createSentryConfiguration (): NodeDefinition
129+ {
130+ $ node = (new TreeBuilder ('sentry ' ))->getRootNode ();
131+ $ node
132+ ->addDefaultsIfNotSet ()
133+ ->children ()
134+ ->booleanNode ('enabled ' )
103135 ->info ('Whether or not to enable passing trace and transaction id to Sentry ' )
104136 ->defaultFalse ()
105137 ->end ()
106138 ->scalarNode ('hub_service ' )
107139 ->info ('The service id of the Sentry Hub. Defaults to Sentry\State\HubInterface ' )
108140 ->defaultValue (HubInterface::class)
109141 ->end ()
110- ->end ()
111- ;
142+ ->end ();
112143
113- return $ tree ;
144+ return $ node ;
114145 }
115146}
0 commit comments