22
33namespace DDTrace \Tests \Unit ;
44
5+ use DDTrace \Exceptions \InvalidSpanArgument ;
56use DDTrace \SpanContext ;
67use DDTrace \Tags ;
78use DDTrace \Span ;
1011
1112final class SpanTest extends PHPUnit_Framework_TestCase
1213{
13- const NAME = 'test_span ' ;
14+ const OPERATION_NAME = 'test_span ' ;
1415 const SERVICE = 'test_service ' ;
1516 const RESOURCE = 'test_resource ' ;
1617 const ANOTHER_NAME = 'test_span2 ' ;
1718 const ANOTHER_SERVICE = 'test_service2 ' ;
1819 const ANOTHER_RESOURCE = 'test_resource2 ' ;
1920 const ANOTHER_TYPE = 'test_type2 ' ;
20- const META_KEY = 'test_key ' ;
21- const META_VALUE = 'test_value ' ;
21+ const TAG_KEY = 'test_key ' ;
22+ const TAG_VALUE = 'test_value ' ;
2223 const EXCEPTION_MESSAGE = 'exception message ' ;
2324
2425 public function testCreateSpanSuccess ()
2526 {
2627 $ span = $ this ->createSpan ();
27- $ span ->setTags ([self ::META_KEY => self ::META_VALUE ]);
28+ $ span ->setTags ([self ::TAG_KEY => self ::TAG_VALUE ]);
2829
29- $ this ->assertSame (self ::NAME , $ span ->getOperationName ());
30+ $ this ->assertSame (self ::OPERATION_NAME , $ span ->getOperationName ());
3031 $ this ->assertSame (self ::SERVICE , $ span ->getService ());
3132 $ this ->assertSame (self ::RESOURCE , $ span ->getResource ());
32- $ this ->assertSame (self ::META_VALUE , $ span ->getTag (self ::META_KEY ));
33+ $ this ->assertSame (self ::TAG_VALUE , $ span ->getTag (self ::TAG_KEY ));
3334 }
3435
3536 public function testOverwriteOperationNameSuccess ()
@@ -39,16 +40,16 @@ public function testOverwriteOperationNameSuccess()
3940 $ this ->assertSame (self ::ANOTHER_NAME , $ span ->getOperationName ());
4041 }
4142
42- public function testSpanMetaRemainsImmutableAfterFinishing ()
43+ public function testSpanTagsRemainImmutableAfterFinishing ()
4344 {
4445 $ span = $ this ->createSpan ();
4546 $ span ->finish ();
4647
47- $ span ->setTags ([self ::META_KEY => self ::META_VALUE ]);
48- $ this ->assertNull ($ span ->getTag (self ::META_KEY ));
48+ $ span ->setTags ([self ::TAG_KEY => self ::TAG_VALUE ]);
49+ $ this ->assertNull ($ span ->getTag (self ::TAG_KEY ));
4950 }
5051
51- public function testSpanErrorAddsExpectedMeta ()
52+ public function testSpanErrorAddsExpectedTags ()
5253 {
5354 $ span = $ this ->createSpan ();
5455 $ span ->setError (new Exception (self ::EXCEPTION_MESSAGE ));
@@ -67,6 +68,14 @@ public function testSpanErrorRemainsImmutableAfterFinishing()
6768 $ this ->assertFalse ($ span ->hasError ());
6869 }
6970
71+ public function testSpanErrorFailsForInvalidError ()
72+ {
73+ $ this ->expectException (InvalidSpanArgument::class);
74+ $ this ->expectExceptionMessage ('Error should be either Exception or Throwable, got integer. ' );
75+ $ span = $ this ->createSpan ();
76+ $ span ->setError (1 );
77+ }
78+
7079 public function testAddCustomTagsSuccess ()
7180 {
7281 $ span = $ this ->createSpan ();
@@ -81,12 +90,20 @@ public function testAddCustomTagsSuccess()
8190 $ this ->assertEquals (self ::ANOTHER_TYPE , $ span ->getType ());
8291 }
8392
93+ public function testAddTagsFailsForInvalidTagKey ()
94+ {
95+ $ this ->expectException (InvalidSpanArgument::class);
96+ $ this ->expectExceptionMessage ('Invalid key type in given span tags. Expected string, got integer. ' );
97+ $ span = $ this ->createSpan ();
98+ $ span ->setTags ([self ::TAG_KEY ]);
99+ }
100+
84101 private function createSpan ()
85102 {
86103 $ context = SpanContext::createAsRoot ();
87104
88105 $ span = new Span (
89- self ::NAME ,
106+ self ::OPERATION_NAME ,
90107 $ context ,
91108 self ::SERVICE ,
92109 self ::RESOURCE
0 commit comments