@@ -57,6 +57,67 @@ public function testInjection()
57
57
]);
58
58
}
59
59
60
+ public function testInjectionServiceMappingOnce ()
61
+ {
62
+ try {
63
+ $ hook = \DDTrace \install_hook (self ::class . "::instrumented " , function (HookData $ hook ) {
64
+ $ span = $ hook ->span ();
65
+ $ span ->service = "pdo " ;
66
+ $ span ->name = "instrumented " ;
67
+ DatabaseIntegrationHelper::injectDatabaseIntegrationData ($ hook , 'mysql ' , 1 );
68
+ });
69
+ self ::putEnv ("DD_TRACE_DEBUG_PRNG_SEED=42 " );
70
+ self ::putEnv ("DD_DBM_PROPAGATION_MODE=full " );
71
+ self ::putEnv ("DD_SERVICE_MAPPING=pdo:mapped-service " );
72
+ $ traces = $ this ->isolateTracer (function () use (&$ commentedQuery ) {
73
+ \DDTrace \start_trace_span ();
74
+ $ commentedQuery = $ this ->instrumented (0 , "SELECT 1 " );
75
+ \DDTrace \close_span ();
76
+ });
77
+ } finally {
78
+ \DDTrace \remove_hook ($ hook );
79
+ }
80
+
81
+ $ this ->assertRegularExpression ('/^\/\*dddbs= \'mapped-service \',ddps= \'phpunit \',traceparent= \'00-[0-9a-f]{16}c151df7d6ee5e2d6-a3978fb9b92502a8-01 \'\*\/ SELECT 1$/ ' , $ commentedQuery );
82
+ $ this ->assertFlameGraph ($ traces , [
83
+ SpanAssertion::exists ("phpunit " )->withChildren ([
84
+ SpanAssertion::exists ('instrumented ' )->withExactTags ([
85
+ "_dd.dbm_trace_injected " => "true " ,
86
+ "_dd.base_service " => "mapped-service " ,
87
+ ])
88
+ ])
89
+ ]);
90
+ }
91
+
92
+ public function testInjectionServiceMappingTwice ()
93
+ {
94
+ try {
95
+ $ hook = \DDTrace \install_hook (self ::class . "::instrumented " , function (HookData $ hook ) {
96
+ $ span = $ hook ->span ();
97
+ $ span ->service = "pdo " ;
98
+ $ span ->name = "instrumented " ;
99
+ DatabaseIntegrationHelper::injectDatabaseIntegrationData ($ hook , 'mysql ' , 1 );
100
+ });
101
+ self ::putEnv ("DD_TRACE_DEBUG_PRNG_SEED=42 " );
102
+ self ::putEnv ("DD_DBM_PROPAGATION_MODE=full " );
103
+ self ::putEnv ("DD_SERVICE_MAPPING=pdo:mapped-service " );
104
+ // Note that here, we don't start a new trace, hence the service mapping should apply to both dddbs & ddps
105
+ $ traces = $ this ->isolateTracer (function () use (&$ commentedQuery ) {
106
+ $ commentedQuery = $ this ->instrumented (0 , "SELECT 1 " );
107
+ });
108
+ } finally {
109
+ \DDTrace \remove_hook ($ hook );
110
+ }
111
+
112
+ $ this ->assertRegularExpression ('/^\/\*dddbs= \'mapped-service \',ddps= \'mapped-service \',traceparent= \'00-[0-9a-f]{16}c151df7d6ee5e2d6-c151df7d6ee5e2d6-01 \'\*\/ SELECT 1$/ ' , $ commentedQuery );
113
+ $ this ->assertFlameGraph ($ traces , [
114
+ SpanAssertion::exists ('instrumented ' )->withExactTags ([
115
+ "_dd.dbm_trace_injected " => "true " ,
116
+ "_dd.base_service " => "mapped-service " ,
117
+ ])
118
+ ]);
119
+ }
120
+
60
121
public function testInjectionPeerService ()
61
122
{
62
123
try {
0 commit comments