99use Illuminate \Support \Facades \Http ;
1010use Illuminate \Support \Facades \Log ;
1111use OpenTelemetry \SemConv \TraceAttributes ;
12+ use OpenTelemetry \Tests \Contrib \Instrumentation \Laravel \Fixtures \Models \TestModel ;
1213
1314/** @psalm-suppress UnusedClass */
1415class LaravelInstrumentationTest extends TestCase
@@ -86,12 +87,6 @@ public function test_cache_log_db(): void
8687
8788 public function test_eloquent_operations (): void
8889 {
89- /** @var class-string<\Illuminate\Database\Eloquent\Model> */
90- $ model = new class () extends \Illuminate \Database \Eloquent \Model {
91- protected $ table = 'test_models ' ;
92- protected $ fillable = ['name ' ];
93- };
94-
9590 // Assert storage is empty before interacting with the database
9691 $ this ->assertCount (0 , $ this ->storage );
9792
@@ -103,16 +98,13 @@ public function test_eloquent_operations(): void
10398 updated_at DATETIME
10499 ) ' );
105100
106- $ this ->router ()->get ('/eloquent ' , function () use ( $ modelClass ) {
101+ $ this ->router ()->get ('/eloquent ' , function () {
107102 try {
108- /** @var \Illuminate\Database\Eloquent\Model $model */
109- $ model = new $ modelClass ();
110-
111103 // Test create
112- $ created = $ modelClass ::create (['name ' => 'test ' ]);
104+ $ created = TestModel ::create (['name ' => 'test ' ]);
113105
114106 // Test find
115- $ found = $ modelClass ::find ($ created ->id );
107+ $ found = TestModel ::find ($ created ->id );
116108
117109 // Test update
118110 $ found ->update (['name ' => 'updated ' ]);
@@ -161,35 +153,35 @@ public function test_eloquent_operations(): void
161153 $ createSpan = array_values (array_filter ($ eloquentSpans , function ($ span ) {
162154 return $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'create ' ;
163155 }))[0 ];
164- $ this ->assertSame ('TestModel::create ' , $ createSpan ->getName ());
165- $ this ->assertSame ('TestModel ' , $ createSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
156+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel::create ' , $ createSpan ->getName ());
157+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel ' , $ createSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
166158 $ this ->assertSame ('test_models ' , $ createSpan ->getAttributes ()->get ('laravel.eloquent.table ' ));
167159 $ this ->assertSame ('create ' , $ createSpan ->getAttributes ()->get ('laravel.eloquent.operation ' ));
168160
169161 // Find span
170162 $ findSpan = array_values (array_filter ($ eloquentSpans , function ($ span ) {
171163 return $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'find ' ;
172164 }))[0 ];
173- $ this ->assertSame ('TestModel::find ' , $ findSpan ->getName ());
174- $ this ->assertSame ('TestModel ' , $ findSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
165+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel::find ' , $ findSpan ->getName ());
166+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel ' , $ findSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
175167 $ this ->assertSame ('test_models ' , $ findSpan ->getAttributes ()->get ('laravel.eloquent.table ' ));
176168 $ this ->assertSame ('find ' , $ findSpan ->getAttributes ()->get ('laravel.eloquent.operation ' ));
177169
178170 // Update span
179171 $ updateSpan = array_values (array_filter ($ eloquentSpans , function ($ span ) {
180172 return $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'update ' ;
181173 }))[0 ];
182- $ this ->assertSame ('TestModel::update ' , $ updateSpan ->getName ());
183- $ this ->assertSame ('TestModel ' , $ updateSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
174+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel::update ' , $ updateSpan ->getName ());
175+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel ' , $ updateSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
184176 $ this ->assertSame ('test_models ' , $ updateSpan ->getAttributes ()->get ('laravel.eloquent.table ' ));
185177 $ this ->assertSame ('update ' , $ updateSpan ->getAttributes ()->get ('laravel.eloquent.operation ' ));
186178
187179 // Delete span
188180 $ deleteSpan = array_values (array_filter ($ eloquentSpans , function ($ span ) {
189181 return $ span ->getAttributes ()->get ('laravel.eloquent.operation ' ) === 'delete ' ;
190182 }))[0 ];
191- $ this ->assertSame ('TestModel::delete ' , $ deleteSpan ->getName ());
192- $ this ->assertSame ('TestModel ' , $ deleteSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
183+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel::delete ' , $ deleteSpan ->getName ());
184+ $ this ->assertSame ('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\ TestModel ' , $ deleteSpan ->getAttributes ()->get ('laravel.eloquent.model ' ));
193185 $ this ->assertSame ('test_models ' , $ deleteSpan ->getAttributes ()->get ('laravel.eloquent.table ' ));
194186 $ this ->assertSame ('delete ' , $ deleteSpan ->getAttributes ()->get ('laravel.eloquent.operation ' ));
195187 }
0 commit comments