good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pggat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gfx
pggat
Commits
b223550c
Commit
b223550c
authored
7 months ago
by
Thomas Guinther
Browse files
Options
Downloads
Patches
Plain Diff
minor re-factorings
parent
2aa30991
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#83778
failed with stages
in 6 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/fed/middlewares/tracing/oteltracer.go
+16
-16
16 additions, 16 deletions
lib/fed/middlewares/tracing/oteltracer.go
lib/fed/middlewares/tracing/pgtrace.go
+2
-2
2 additions, 2 deletions
lib/fed/middlewares/tracing/pgtrace.go
with
18 additions
and
18 deletions
lib/fed/middlewares/tracing/oteltracer.go
+
16
−
16
View file @
b223550c
...
...
@@ -12,22 +12,22 @@ import (
"log/slog"
)
type
State
int
type
query
State
int
const
(
Init
State
=
iota
Init
query
State
=
iota
Waiting
Query
)
type
otel
t
race
struct
{
state
State
type
otel
T
race
struct
{
state
query
State
tracer
trace
.
Tracer
span
trace
.
Span
}
func
NewOtelTrace
(
ctx
context
.
Context
)
fed
.
Middleware
{
return
&
otel
t
race
{
return
&
otel
T
race
{
tracer
:
otel
.
Tracer
(
"pggat"
,
trace
.
WithInstrumentationAttributes
(
...
...
@@ -35,25 +35,25 @@ func NewOtelTrace(ctx context.Context) fed.Middleware {
}
}
func
(
t
*
otel
t
race
)
ReadPacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
func
(
t
*
otel
T
race
)
ReadPacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
t
.
process
(
ctx
,
packet
)
return
packet
,
nil
}
func
(
t
*
otel
t
race
)
WritePacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
func
(
t
*
otel
T
race
)
WritePacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
t
.
process
(
ctx
,
packet
)
return
packet
,
nil
}
func
(
t
*
otel
t
race
)
PreRead
(
ctx
context
.
Context
,
_
bool
)
(
fed
.
Packet
,
error
)
{
func
(
t
*
otel
T
race
)
PreRead
(
ctx
context
.
Context
,
_
bool
)
(
fed
.
Packet
,
error
)
{
return
nil
,
nil
}
func
(
t
*
otel
t
race
)
PostWrite
(
ctx
context
.
Context
)
(
fed
.
Packet
,
error
)
{
func
(
t
*
otel
T
race
)
PostWrite
(
ctx
context
.
Context
)
(
fed
.
Packet
,
error
)
{
return
nil
,
nil
}
func
(
t
*
otel
t
race
)
process
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
func
(
t
*
otel
T
race
)
process
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
switch
t
.
state
{
case
Init
:
switch
packet
.
Type
()
{
...
...
@@ -79,7 +79,7 @@ func (t *oteltrace) process(ctx context.Context, packet fed.Packet) {
}
}
func
getStateName
(
state
State
)
(
str
string
)
{
func
getStateName
(
state
query
State
)
(
str
string
)
{
switch
state
{
case
Init
:
str
=
"Init"
...
...
@@ -94,12 +94,12 @@ func getStateName(state State) (str string) {
return
}
func
(
t
*
otel
t
race
)
setState
(
ctx
context
.
Context
,
state
State
)
{
func
(
t
*
otel
T
race
)
setState
(
ctx
context
.
Context
,
state
query
State
)
{
slog
.
Warn
(
fmt
.
Sprintf
(
"State Change: %s => %s"
,
getStateName
(
t
.
state
),
getStateName
(
state
)))
t
.
state
=
state
}
func
(
t
*
otel
t
race
)
startQuery
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
func
(
t
*
otel
T
race
)
startQuery
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
sql
:=
"<unresolved>"
if
pp
,
ok
:=
packet
.
(
fed
.
PendingPacket
);
ok
{
...
...
@@ -119,14 +119,14 @@ func (t *oteltrace) startQuery(ctx context.Context, packet fed.Packet) {
trace
.
WithAttributes
(
attribute
.
String
(
"sql"
,
sql
)))
}
func
(
t
*
otel
t
race
)
endQuery
(
ctx
context
.
Context
)
{
func
(
t
*
otel
T
race
)
endQuery
(
ctx
context
.
Context
)
{
if
t
.
span
!=
nil
{
t
.
span
.
End
()
t
.
span
=
nil
}
}
func
(
t
*
otel
t
race
)
recordError
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
func
(
t
*
otel
T
race
)
recordError
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
errMsg
:=
"<unresolved error message>"
if
pp
,
ok
:=
packet
.
(
fed
.
PendingPacket
);
ok
{
...
...
@@ -145,7 +145,7 @@ func (t *oteltrace) recordError(ctx context.Context, packet fed.Packet) {
t
.
span
.
SetStatus
(
codes
.
Error
,
errMsg
)
}
func
(
t
*
otel
t
race
)
recordSummary
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
func
(
t
*
otel
T
race
)
recordSummary
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
{
summary
:=
"<unresolved query summary>"
if
pp
,
ok
:=
packet
.
(
fed
.
PendingPacket
);
ok
{
...
...
This diff is collapsed.
Click to expand it.
lib/fed/middlewares/tracing/pgtrace.go
+
2
−
2
View file @
b223550c
...
...
@@ -12,12 +12,12 @@ func NewPgTrace(ctx context.Context) fed.Middleware {
}
func
(
t
*
pgtrace
)
ReadPacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
logPacket
(
"Read
Packet
"
,
packet
)
logPacket
(
"Read "
,
packet
)
return
packet
,
nil
}
func
(
t
*
pgtrace
)
WritePacket
(
ctx
context
.
Context
,
packet
fed
.
Packet
)
(
fed
.
Packet
,
error
)
{
logPacket
(
"Write
Packet
"
,
packet
)
logPacket
(
"Write"
,
packet
)
return
packet
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment