- Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgraph_telemetry_handler.go
50 lines (45 loc) · 1.56 KB
/
graph_telemetry_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package msgraphgocore
import (
nethttp "net/http"
runtime "runtime"
uuid "github.com/google/uuid"
khttp "github.com/microsoft/kiota-http-go"
)
// GraphTelemetryHandler is a middleware handler that adds telemetry headers to requests.
typeGraphTelemetryHandlerstruct {
sdkVersionstring
}
// NewGraphTelemetryHandler creates a new GraphTelemetryHandler.
funcNewGraphTelemetryHandler(options*GraphClientOptions) *GraphTelemetryHandler {
serviceVersionPrefix:=""
ifoptions!=nil&&options.GraphServiceLibraryVersion!="" {
serviceVersionPrefix+="graph-go"
ifoptions.GraphServiceVersion!="" {
serviceVersionPrefix+="-"+options.GraphServiceVersion
}
serviceVersionPrefix+="/"+options.GraphServiceLibraryVersion
serviceVersionPrefix+=", "
}
featuresSuffix:=""
ifruntime.GOOS!="" {
featuresSuffix+=" hostOS="+runtime.GOOS+";"
}
ifruntime.GOARCH!="" {
featuresSuffix+=" hostArch="+runtime.GOARCH+";"
}
goVersion:=runtime.Version()
ifgoVersion!="" {
featuresSuffix+=" runtimeEnvironment="+goVersion+";"
}
iffeaturesSuffix!="" {
featuresSuffix=" ("+featuresSuffix[1:] +")"
}
return&GraphTelemetryHandler{
sdkVersion: serviceVersionPrefix+"graph-go-core/"+CoreVersion+featuresSuffix,
}
}
func (middlewareGraphTelemetryHandler) Intercept(pipeline khttp.Pipeline, middlewareIndexint, req*nethttp.Request) (*nethttp.Response, error) {
req.Header.Add("SdkVersion", middleware.sdkVersion)
req.Header.Add("client-request-id", uuid.NewString())
returnpipeline.Next(req, middlewareIndex)
}