@@ -78,31 +78,26 @@ public function test_create(): void
7878 $ this ->assertSame ('create ' , $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ));
7979 }
8080
81- public function test_find_and_get_models (): void
81+ public function test_find (): void
8282 {
8383 TestModel::find (1 );
8484
85- $ spans = $ this ->filterOnlyEloquentSpans ();
86-
8785 // spans contains 2 eloquent spans for 'find' and 'get', because it method internally calls 'getModels' method.
88- $ this ->assertCount (2 , $ spans );
89-
90- foreach ($ spans as $ span ) {
91- $ this ->assertSame (
92- 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel ' ,
93- $ span ->getAttributes ()->get ('laravel.eloquent.model ' )
94- );
95- $ this ->assertSame ('test_models ' , $ span ->getAttributes ()->get ('laravel.eloquent.table ' ));
96-
97- $ operation = $ span ->getAttributes ()->get ('laravel.eloquent.operation ' );
98- $ this ->assertSame (
99- match ($ operation ) {
100- 'find ' => 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::find ' ,
101- 'get ' => 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::get '
102- },
103- $ span ->getName (),
104- );
105- }
86+ // So, filtering span only find span.
87+ $ spans = array_filter (
88+ $ this ->filterOnlyEloquentSpans (),
89+ fn ($ span ) => $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'find '
90+ );
91+
92+
93+ $ this ->assertCount (1 , $ spans );
94+
95+ $ span = $ spans [0 ];
96+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::find ' , $ span ->getName ());
97+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel ' , $ span ->getAttributes ()->get ('laravel.eloquent.model ' ));
98+ $ this ->assertSame ('test_models ' , $ span ->getAttributes ()->get ('laravel.eloquent.table ' ));
99+ $ this ->assertSame ('find ' , $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ));
100+
106101 }
107102
108103 public function test_perform_insert (): void
@@ -160,24 +155,19 @@ public function test_destory(): void
160155 $ spans = $ this ->filterOnlyEloquentSpans ();
161156
162157 // spans contains 2 eloquent spans for 'destroy' and 'get', because it method internally calls 'getModels' method.
163- $ this ->assertCount (2 , $ spans );
164-
165- foreach ($ spans as $ span ) {
166- $ this ->assertSame (
167- 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel ' ,
168- $ span ->getAttributes ()->get ('laravel.eloquent.model ' )
169- );
170- $ this ->assertSame ('test_models ' , $ span ->getAttributes ()->get ('laravel.eloquent.table ' ));
171-
172- $ operation = $ span ->getAttributes ()->get ('laravel.eloquent.operation ' );
173- $ this ->assertSame (
174- match ($ operation ) {
175- 'destroy ' => 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::destroy ' ,
176- 'get ' => 'OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::get '
177- },
178- $ span ->getName (),
179- );
180- }
158+ // So, filtering span only 'destroy' span.
159+ $ spans = array_filter (
160+ $ this ->filterOnlyEloquentSpans (),
161+ fn ($ span ) => $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'destroy '
162+ );
163+
164+ $ this ->assertCount (1 , $ spans );
165+
166+ $ span = $ spans [0 ];
167+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::destroy ' , $ span ->getName ());
168+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel ' , $ span ->getAttributes ()->get ('laravel.eloquent.model ' ));
169+ $ this ->assertSame ('test_models ' , $ span ->getAttributes ()->get ('laravel.eloquent.table ' ));
170+ $ this ->assertSame ('destroy ' , $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ));
181171 }
182172
183173 public function test_refresh (): void
0 commit comments