Debian Codegraph @

receiver/otlpreceiver/internal/profiles/otlp.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package profiles // import "go.opentelemetry.io/collector/receiver/otlpreceiver/internal/profiles"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/collector/consumer/xconsumer"
10 "go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp"
11 "go.opentelemetry.io/collector/receiver/otlpreceiver/internal/errors"
12 )
13
14 // Receiver is the type used to handle spans from OpenTelemetry exporters.
15 type Receiver struct {
16 pprofileotlp.UnimplementedGRPCServer
17 nextConsumer xconsumer.Profiles
18 }
19
20 // New creates a new Receiver reference.
21 func New(nextConsumer xconsumer.Profiles) *Receiver {
22 return &Receiver{
23 nextConsumer: nextConsumer,
24 }
25 }
26
27 // Export implements the service Export profiles func.
28 func (r *Receiver) Export(ctx context.Context, req pprofileotlp.ExportRequest) (pprofileotlp.ExportResponse, error) {
29 td := req.Profiles()
30 // We need to ensure that it propagates the receiver name as a tag
31 numProfiles := td.SampleCount()
32 if numProfiles == 0 {
33 return pprofileotlp.NewExportResponse(), nil
34 }
35
36 err := r.nextConsumer.ConsumeProfiles(ctx, td)
37 // Use appropriate status codes for permanent/non-permanent errors
38 // If we return the error straightaway, then the grpc implementation will set status code to Unknown
39 // Refer: https://github.com/grpc/grpc-go/blob/v1.59.0/server.go#L1345
40 // So, convert the error to appropriate grpc status and return the error
41 // NonPermanent errors will be converted to codes.Unavailable (equivalent to HTTP 503)
42 // Permanent errors will be converted to codes.InvalidArgument (equivalent to HTTP 400)
43 if err != nil {
44 return pprofileotlp.NewExportResponse(), errors.GetStatusFromError(err)
45 }
46
47 return pprofileotlp.NewExportResponse(), nil
48 }