-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7e6953
commit 94263a5
Showing
8 changed files
with
237 additions
and
48 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/OpenTelemetry-Instrumentation-Tests/OTAbstractInstrumentationTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Class { | ||
#name : 'OTAbstractInstrumentationTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'target' | ||
], | ||
#category : 'OpenTelemetry-Instrumentation-Tests', | ||
#package : 'OpenTelemetry-Instrumentation-Tests' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
OTAbstractInstrumentationTest >> instrumentationClass [ | ||
|
||
self subclassResponsibility | ||
] | ||
|
||
{ #category : 'running' } | ||
OTAbstractInstrumentationTest >> setUp [ | ||
|
||
super setUp. | ||
self instrumentationClass install. | ||
target := OTTestTarget new | ||
] | ||
|
||
{ #category : 'running' } | ||
OTAbstractInstrumentationTest >> tearDown [ | ||
|
||
self instrumentationClass uninstall. | ||
super tearDown | ||
] |
22 changes: 22 additions & 0 deletions
22
src/OpenTelemetry-Instrumentation-Tests/OTSampledInstrumentationTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Class { | ||
#name : 'OTSampledInstrumentationTest', | ||
#superclass : 'OTAbstractInstrumentationTest', | ||
#category : 'OpenTelemetry-Instrumentation-Tests', | ||
#package : 'OpenTelemetry-Instrumentation-Tests' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
OTSampledInstrumentationTest >> instrumentationClass [ | ||
|
||
^ OTTestSampledInstrumentation | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSampledInstrumentationTest >> testFixedRateSampler [ | ||
|
||
self deny: OTTestSampledInstrumentation hasRunOnEnter. | ||
target answer. | ||
self deny: OTTestSampledInstrumentation hasRunOnEnter. | ||
target answer. | ||
self assert: OTTestSampledInstrumentation hasRunOnEnter | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 92 additions & 9 deletions
101
src/OpenTelemetry-Instrumentation-Tests/OTSpanInstrumentationTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,117 @@ | ||
Class { | ||
#name : 'OTSpanInstrumentationTest', | ||
#superclass : 'TestCase', | ||
#superclass : 'OTAbstractInstrumentationTest', | ||
#instVars : [ | ||
'target' | ||
'currentProcessor' | ||
], | ||
#category : 'OpenTelemetry-Instrumentation-Tests', | ||
#package : 'OpenTelemetry-Instrumentation-Tests' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
OTSpanInstrumentationTest >> instrumentationClass [ | ||
|
||
^ OTTestSpanInstrumentation | ||
] | ||
|
||
{ #category : 'running' } | ||
OTSpanInstrumentationTest >> setUp [ | ||
"Remember the configured processor." | ||
|
||
super setUp. | ||
OTTestSpanInstrumentation install. | ||
target := OTTestTarget new | ||
currentProcessor := OTSpanProcessor current. | ||
OTBatchSpanProcessor new beCurrent | ||
] | ||
|
||
{ #category : 'running' } | ||
OTSpanInstrumentationTest >> tearDown [ | ||
"Restore the configured processor." | ||
|
||
OTTestSpanInstrumentation uninstall. | ||
currentProcessor beCurrent. | ||
super tearDown | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testFixedRateSampler [ | ||
OTSpanInstrumentationTest >> testDefaultSpanKind [ | ||
|
||
self deny: OTTestSpanInstrumentation hasRunOnEnter. | ||
target answer. | ||
self deny: OTTestSpanInstrumentation hasRunOnEnter. | ||
self | ||
assert: OTTestSpanInstrumentation capturedSpan kind | ||
equals: OTSpan internal | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testDefaultSpanName [ | ||
|
||
target answer. | ||
self | ||
assert: OTTestSpanInstrumentation capturedSpan name | ||
equals: (OTTestTarget >> #answer) name | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testRecordException [ | ||
|
||
| error span | | ||
[ target fail ] | ||
on: Error | ||
do: [ :err | error := err ]. | ||
span := OTTestSpanInstrumentation capturedSpan. | ||
self assert: span status equals: 'ERROR'. | ||
self | ||
assert: (span attributes at: 'exception') | ||
equals: error description | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testSpanAttributes [ | ||
"Attributes were created and populated on method enter and exit." | ||
|
||
| attributes | | ||
target answer. | ||
self assert: OTTestSpanInstrumentation hasRunOnEnter | ||
attributes := OTTestSpanInstrumentation capturedSpan attributes. | ||
self assert: attributes isNotNil. | ||
self assert: (attributes includesKey: 'enter'). | ||
self assert: (attributes at: 'enter') equals: #OK. | ||
self assert: (attributes includesKey: 'exit'). | ||
self assert: (attributes at: 'exit') equals: #OK | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testSpanExists [ | ||
|
||
self assert: OTTestSpanInstrumentation capturedSpan isNil. | ||
target answer. | ||
self | ||
assert: OTTestSpanInstrumentation capturedSpan class | ||
identicalTo: OTSpan | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testSpanLifetime [ | ||
|
||
| span | | ||
target answer. | ||
span := OTTestSpanInstrumentation capturedSpan. | ||
self assert: span startTime isNotNil. | ||
self assert: span endTime isNotNil. | ||
self assert: span startTime <= span endTime | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testSpanStatus [ | ||
|
||
target answer. | ||
self | ||
assert: OTTestSpanInstrumentation capturedSpan status | ||
equals: #OK | ||
] | ||
|
||
{ #category : 'tests' } | ||
OTSpanInstrumentationTest >> testSpanSuppression [ | ||
|
||
| span | | ||
target suppressedAnswer. | ||
span := OTTestSpanInstrumentation capturedSpan. | ||
self assert: (span attributes includesKey: 'suppressed') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/OpenTelemetry-Instrumentation-Tests/OTTestSampledInstrumentation.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Class { | ||
#name : 'OTTestSampledInstrumentation', | ||
#superclass : 'OTTestInstrumentation', | ||
#category : 'OpenTelemetry-Instrumentation-Tests', | ||
#package : 'OpenTelemetry-Instrumentation-Tests' | ||
} | ||
|
||
{ #category : 'configuring' } | ||
OTTestSampledInstrumentation class >> defineSampler [ | ||
|
||
sampler := OTSampler withRate: 2 | ||
] |
44 changes: 40 additions & 4 deletions
44
src/OpenTelemetry-Instrumentation-Tests/OTTestSpanInstrumentation.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,54 @@ | ||
Class { | ||
#name : 'OTTestSpanInstrumentation', | ||
#superclass : 'OTTestInstrumentation', | ||
#classInstVars : [ | ||
'capturedSpan', | ||
'suppressed' | ||
], | ||
#category : 'OpenTelemetry-Instrumentation-Tests', | ||
#package : 'OpenTelemetry-Instrumentation-Tests' | ||
} | ||
|
||
{ #category : 'instrumenting' } | ||
OTTestSpanInstrumentation class >> capturedSpan [ | ||
|
||
^ capturedSpan | ||
] | ||
|
||
{ #category : 'configuring' } | ||
OTTestSpanInstrumentation class >> defineInstrumenter [ | ||
|
||
instrumenter := OTInstrumenter forInstrumentationNamed: 'test' | ||
instrumenter := OTInstrumenter forInstrumentationNamed: 'test'. | ||
instrumenter spanSuppressionStrategy: [ :span :kind | | ||
span isNotNil and: [ span name includesSubstring: 'suppressed' ] ] | ||
] | ||
|
||
{ #category : 'configuring' } | ||
OTTestSpanInstrumentation class >> defineSampler [ | ||
{ #category : 'instrumenting' } | ||
OTTestSpanInstrumentation class >> onMethodEnter: event [ | ||
|
||
| request | | ||
request := event first method. | ||
(suppressed := (instrumenter | ||
shouldStartUnder: OTSpan current | ||
request: request) not) ifTrue: [ | ||
^ capturedSpan attributeAt: 'suppressed' put: true ]. | ||
capturedSpan := instrumenter startRequest: request. | ||
capturedSpan attributeAt: 'enter' put: #OK | ||
] | ||
|
||
{ #category : 'instrumenting' } | ||
OTTestSpanInstrumentation class >> onMethodExit: event withValue: returnValue [ | ||
|
||
suppressed ifTrue: [ "suppress only once" ^ suppressed := false ]. | ||
capturedSpan attributeAt: 'exit' put: #OK. | ||
capturedSpan status ifNil: [ capturedSpan setOkStatus ]. | ||
instrumenter end: capturedSpan | ||
] | ||
|
||
{ #category : 'class initialization' } | ||
OTTestSpanInstrumentation class >> reset [ | ||
|
||
sampler := OTSampler withRate: 2 | ||
super reset. | ||
capturedSpan := nil. | ||
suppressed := false | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters