Skip to content

Commit

Permalink
Merge a06a046
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Darbord committed Nov 13, 2024
2 parents 611a758 + a06a046 commit d0ad716
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #FamixStMethod }
Extension { #name : 'FamixStMethod' }

{ #category : #'*Famix-OpenTelemetry-Importer-Value' }
{ #category : '*Famix-OpenTelemetry-Importer-Value' }
FamixStMethod >> sortedParameters [

^ parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #FamixTWithParameters }
Extension { #name : 'FamixTWithParameters' }

{ #category : #'*Famix-OpenTelemetry-Importer-Value' }
{ #category : '*Famix-OpenTelemetry-Importer-Value' }
FamixTWithParameters >> sortedParameters [

^ parameters sorted: [ :a :b |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ I am a post-transformer that links `Span`s to their origin in a Famix model, and
The arguments and result information is recovered from the tags using the configured keys.
"
Class {
#name : #OTelFamixValueLinker,
#superclass : #OTelFamixLinker,
#name : 'OTelFamixValueLinker',
#superclass : 'OTelFamixLinker',
#instVars : [
'argsKey',
'resultKey',
'shouldLinkResultFirst',
'shouldResetImporter',
'receiverKey'
],
#category : #'Famix-OpenTelemetry-Importer-Value'
#category : 'Famix-OpenTelemetry-Importer-Value',
#package : 'Famix-OpenTelemetry-Importer-Value'
}

{ #category : #accessing }
{ #category : 'accessing' }
OTelFamixValueLinker >> argsKey: aString [

argsKey := aString
]

{ #category : #links }
{ #category : 'links' }
OTelFamixValueLinker >> linkArguments: span [
"Link the serialized arguments to the Famix model."

Expand All @@ -38,7 +39,7 @@ OTelFamixValueLinker >> linkArguments: span [
span: span ] ]
]

{ #category : #transforming }
{ #category : 'links' }
OTelFamixValueLinker >> linkReceiver: span [

receiverKey ifNil: [ ^ self ].
Expand All @@ -47,7 +48,7 @@ OTelFamixValueLinker >> linkReceiver: span [
span ]
]

{ #category : #links }
{ #category : 'links' }
OTelFamixValueLinker >> linkResult: span [
"Link the serialized result to the Famix model."

Expand All @@ -58,59 +59,56 @@ OTelFamixValueLinker >> linkResult: span [
resultInSpan: span ]
]

{ #category : #transforming }
{ #category : 'links' }
OTelFamixValueLinker >> linkSpan: span [

importer reset.
self linkOrigin: span.
self linkReceiver: span.
self shouldResetImporter ifTrue: [ importer reset ].
self shouldLinkResultFirst
ifTrue: [ self linkResult: span ]
ifFalse: [ self linkArguments: span ].
self shouldResetImporter ifTrue: [ importer reset ].
self shouldLinkResultFirst
ifTrue: [ self linkArguments: span ]
ifFalse: [ self linkResult: span ]
]

{ #category : 'accessing' }
OTelFamixValueLinker >> receiverKey: aString [

receiverKey := aString
]

{ #category : #accessing }
{ #category : 'accessing' }
OTelFamixValueLinker >> resultKey: aString [

resultKey := aString
]

{ #category : #transforming }
{ #category : 'accessing' }
OTelFamixValueLinker >> shouldLinkResultFirst [

^ shouldLinkResultFirst ifNil: [ shouldLinkResultFirst := true ]
]

{ #category : #transforming }
{ #category : 'accessing' }
OTelFamixValueLinker >> shouldLinkResultFirst: aBoolean [
"Whether to link the result before the arguments."

shouldLinkResultFirst := aBoolean
]

{ #category : #transforming }
{ #category : 'accessing' }
OTelFamixValueLinker >> shouldResetImporter [

^ shouldResetImporter ifNil: [ shouldResetImporter := true ]
]

{ #category : #transforming }
{ #category : 'accessing' }
OTelFamixValueLinker >> shouldResetImporter: aBoolean [
"Whether the importer should be reset between linking the result and arguments."

shouldResetImporter := aBoolean
]

{ #category : #transforming }
OTelFamixValueLinker >> value: model [
"Link trace model with a Famix model using class, method, args and result tags."

model allSpans do: [ :span |
importer reset.
self linkOrigin: span.
self linkReceiver: span.
self shouldResetImporter ifTrue: [ importer reset ].
self shouldLinkResultFirst
ifTrue: [ self linkResult: span ]
ifFalse: [ self linkArguments: span ].
self shouldResetImporter ifTrue: [ importer reset ].
self shouldLinkResultFirst
ifTrue: [ self linkArguments: span ]
ifFalse: [ self linkResult: span ] ].
^ model
]
2 changes: 1 addition & 1 deletion src/Famix-OpenTelemetry-Importer-Value/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Famix-OpenTelemetry-Importer-Value' }
Package { #name : 'Famix-OpenTelemetry-Importer-Value' }
8 changes: 7 additions & 1 deletion src/Famix-OpenTelemetry-Importer/OTelFamixLinker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ OTelFamixLinker >> linkOrigin: span [
in: (importer loadTypeNamed: (span tags at: classKey)))
]

{ #category : 'links' }
OTelFamixLinker >> linkSpan: span [

self linkOrigin: span
]

{ #category : 'accessing' }
OTelFamixLinker >> methodKey: aString [

Expand All @@ -45,6 +51,6 @@ OTelFamixLinker >> methodKey: aString [
OTelFamixLinker >> value: model [
"Link trace model with a Java model using class and method tags."

model allSpans do: [ :span | self linkOrigin: span ].
model allSpans do: [ :span | self linkSpan: span ].
^ model
]
3 changes: 2 additions & 1 deletion src/Famix-OpenTelemetry-Importer/OTelQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ OTelQuery >> removeSpan: span [
span trace: nil.
span context: nil.
parent := span parent.
span children do: [ :child | child parent: parent ].
span children do: [ :child |
child ifNotNil: [ child parent: parent ] ].
span parent: nil.
span mooseModel remove: span
]
Expand Down
52 changes: 52 additions & 0 deletions src/Famix-OpenTelemetry-Importer/OTelTopNQuery.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"
I group spans with my `selector` block, sort them with my `comparator` (or do not sort if not provided), and keep only the top `count`.
"
Class {
#name : 'OTelTopNQuery',
#superclass : 'OTelQuery',
#instVars : [
'comparator',
'count'
],
#category : 'Famix-OpenTelemetry-Importer',
#package : 'Famix-OpenTelemetry-Importer'
}

{ #category : 'accessing' }
OTelTopNQuery >> comparator [
"If not specified, do not sort"

^ comparator
]

{ #category : 'accessing' }
OTelTopNQuery >> comparator: aTwoArgsBlock [

comparator := aTwoArgsBlock
]

{ #category : 'transforming' }
OTelTopNQuery >> count [

^ count ifNil: [ count := 1 ]
]

{ #category : 'transforming' }
OTelTopNQuery >> count: anInteger [

count := anInteger max: 1
]

{ #category : 'transforming' }
OTelTopNQuery >> value: model [
"Only keep the top n of each group in the model."

(model allSpans groupedBy: self selector) do: [ :spans |
| sortedSpans |
sortedSpans := self comparator
ifNil: [ spans ]
ifNotNil: [ :comp | spans sorted: comp ].
self count + 1 to: spans size do: [ :i |
self removeSpan: (sortedSpans at: i) ] ].
^ model
]
37 changes: 36 additions & 1 deletion src/Famix-OpenTelemetry-Importer/OTelZipkinExtractor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Class {
#package : 'Famix-OpenTelemetry-Importer'
}

{ #category : 'parameters' }
OTelZipkinExtractor >> endTs [

^ self parameters at: 'endTs' ifAbsent: [ nil ]
]

{ #category : 'parameters' }
OTelZipkinExtractor >> endTs: anInteger [
"Only return traces where all timestamp are at or before this time in epoch milliseconds."
Expand Down Expand Up @@ -43,12 +49,24 @@ OTelZipkinExtractor >> extract [
^ (NeoJSONReader on: data readStream) parseList
]

{ #category : 'parameters' }
OTelZipkinExtractor >> limit [

^ self parameters at: 'limit' ifAbsent: [ nil ]
]

{ #category : 'parameters' }
OTelZipkinExtractor >> limit: anInteger [

self parameters at: 'limit' put: anInteger
]

{ #category : 'parameters' }
OTelZipkinExtractor >> lookback [

^ self parameters at: 'lookback' ifAbsent: [ nil ]
]

{ #category : 'parameters' }
OTelZipkinExtractor >> lookback: anInteger [
"Only return traces where all timestamp are at or after `endTs - lookback`, in milliseconds."
Expand All @@ -68,7 +86,18 @@ OTelZipkinExtractor >> request [
^ String streamContents: [ :stream |
stream << endpoint << '/api/v2/traces?'.
self parameters associationsDo: [ :param |
stream << $& << param key << $= << param value asString ] ]
stream << $& << param key << $= << param value asString ].
"if not explicitly set, use endTs as current time"
parameters at: 'endTs' ifAbsent: [
stream << '&endTs='.
(DateAndTime now - DateAndTime unixEpoch) asMilliSeconds
printOn: stream ] ]
]

{ #category : 'parameters' }
OTelZipkinExtractor >> serviceName [

^ self parameters at: 'serviceName' ifAbsent: [ nil ]
]

{ #category : 'parameters' }
Expand All @@ -77,6 +106,12 @@ OTelZipkinExtractor >> serviceName: aString [
self parameters at: 'serviceName' put: aString
]

{ #category : 'parameters' }
OTelZipkinExtractor >> spanName [

^ self parameters at: 'spanName' ifAbsent: [ nil ]
]

{ #category : 'parameters' }
OTelZipkinExtractor >> spanName: aString [

Expand Down
5 changes: 2 additions & 3 deletions src/Famix-OpenTelemetry-Importer/OTelZipkinLoader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ OTelZipkinLoader >> loadSpan: rawSpan [
tags: (rawSpan at: 'tags');
timestamp: (rawSpan at: 'timestamp');
duration: (rawSpan at: 'duration').
rawSpan
at: 'parentId'
ifPresent: [ :pid | span parent: (entityDict at: pid) ].
rawSpan at: 'parentId' ifPresent: [ :pid |
entityDict at: pid ifPresent: [ :parent | span parent: parent ] ].
^ entityDict at: span id put: span
]

Expand Down

0 comments on commit d0ad716

Please sign in to comment.