Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export labels #53

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions exporter/metric/cloudmonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ func NewRawExporter(opts ...Option) (*Exporter, error) {
func (e *Exporter) Export(ctx context.Context, cps export.CheckpointSet) error {
return e.metricExporter.ExportMetrics(ctx, cps)
}

// ExportMonitoredResLabels exports the labels of monitored resources.
func (e *Exporter) ExportMonitoredResLabels() map[string]string {
return e.metricExporter.ExportMonitoredResLabels()
}
26 changes: 26 additions & 0 deletions exporter/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (

var (
errBlankProjectID = errors.New("expecting a non-blank ProjectID")
monitoredResLabelMap = make(map[string]string)
)

type errUnsupportedAggregation struct {
Expand Down Expand Up @@ -127,6 +128,7 @@ func InstallNewPipeline(opts []Option, popts ...push.Option) (*push.Controller,
// chaining a NewRawExporter into the recommended selectors and integrators.
func NewExportPipeline(opts []Option, popts ...push.Option) (*push.Controller, error) {
selector := simple.NewWithExactDistribution()
extractResourceLabels(popts...)
exporter, err := NewRawExporter(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -256,6 +258,30 @@ func (me *metricExporter) recordToTspb(r *export.Record, res *resource.Resource)
}, nil
}

// extractResourceLabels extracts resources from the construction option
func extractResourceLabels(popts ...push.Option) {
for _, popt := range popts {
var config push.Config
popt.Apply(&config)
if config.Resource.Len() > 0 {
for _, ele := range config.Resource.Attributes() {
monitoredResLabelMap[string(ele.Key)] = ele.Value.AsString()
}
}
}
}


// ExportMonitoredResLabels exports the map of monitored resources labels
func (me *metricExporter) ExportMonitoredResLabels() map[string]string {
outputMap := make(map[string]string)
// Do deep copy to protect the label map
for k,v := range monitoredResLabelMap {
outputMap[k] = v
}
return outputMap
}

// descToMetricType converts descriptor to MetricType proto type.
// Basically this returns default value ("custom.googleapis.com/opentelemetry/[metric type]")
func (me *metricExporter) descToMetricType(desc *apimetric.Descriptor) string {
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/trace_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func protoFromSpanData(s *export.SpanData, projectID string) *tracepb.Span {
SameProcessAsParentSpan: &wrapperspb.BoolValue{Value: !s.HasRemoteParent},
}
if s.ParentSpanID != s.SpanContext.SpanID && s.ParentSpanID.IsValid() {
sp.ParentSpanId = fmt.Sprintf("%.16x", s.ParentSpanID)
sp.ParentSpanId = s.ParentSpanID.String()
}
if s.StatusCode != codes.OK {
sp.Status = &statuspb.Status{Code: int32(s.StatusCode)}
Expand Down