1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-10-31 00:07:40 +02:00

Remove log interface from Span.

This commit is contained in:
rahulpa
2019-06-19 11:12:31 -07:00
parent 3c3532fb04
commit a551f0298c
7 changed files with 1 additions and 95 deletions

View File

@@ -1,66 +0,0 @@
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package log
import (
"context"
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/scope"
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
)
type (
Interface interface {
Log(ctx context.Context, msg string, fields ...core.KeyValue)
Logf(ctx context.Context, fmt string, args ...interface{})
}
Logger struct {
scope.Scope
}
)
func With(scope scope.Scope) Logger {
return Logger{scope}
}
func Log(ctx context.Context, msg string, fields ...core.KeyValue) {
With(scope.Active(ctx)).Log(ctx, msg, fields...)
}
func Logf(ctx context.Context, fmt string, args ...interface{}) {
With(scope.Active(ctx)).Logf(ctx, fmt, args...)
}
func (l Logger) Log(ctx context.Context, msg string, fields ...core.KeyValue) {
observer.Record(observer.Event{
Type: observer.LOG_EVENT,
Scope: l.ScopeID(),
String: msg,
Attributes: fields,
Context: ctx,
})
}
func (l Logger) Logf(ctx context.Context, fmt string, args ...interface{}) {
observer.Record(observer.Event{
Type: observer.LOGF_EVENT,
Scope: l.ScopeID(),
String: fmt,
Arguments: args,
Context: ctx,
})
}

View File

@@ -21,7 +21,6 @@ import (
"google.golang.org/grpc/codes"
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/log"
"github.com/open-telemetry/opentelemetry-go/api/scope"
"github.com/open-telemetry/opentelemetry-go/api/stats"
"github.com/open-telemetry/opentelemetry-go/api/tag"
@@ -51,8 +50,6 @@ type (
Span interface {
scope.Mutable
log.Interface
stats.Interface
SetError(bool)

View File

@@ -20,7 +20,6 @@ import (
"google.golang.org/grpc/codes"
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/log"
"github.com/open-telemetry/opentelemetry-go/api/stats"
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
)
@@ -167,14 +166,6 @@ func (sp *span) Tracer() Tracer {
return sp.tracer
}
func (sp *span) Log(ctx context.Context, msg string, args ...core.KeyValue) {
log.With(sp).Log(ctx, msg, args...)
}
func (sp *span) Logf(ctx context.Context, fmt string, args ...interface{}) {
log.With(sp).Logf(ctx, fmt, args...)
}
func (sp *span) Record(ctx context.Context, m ...core.Measurement) {
stats.With(sp).Record(ctx, m...)
}

View File

@@ -23,7 +23,6 @@ import (
"google.golang.org/grpc/codes"
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/log"
"github.com/open-telemetry/opentelemetry-go/api/scope"
"github.com/open-telemetry/opentelemetry-go/api/tag"
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
@@ -90,7 +89,6 @@ func (t *tracer) WithSpan(ctx context.Context, name string, body func(context.Co
if err := body(ctx); err != nil {
span.SetAttribute(ErrorKey.Bool(true))
log.Log(ctx, "span error", MessageKey.String(err.Error()))
return err
}
return nil

View File

@@ -17,7 +17,6 @@ package main
import (
"context"
"github.com/open-telemetry/opentelemetry-go/api/log"
"github.com/open-telemetry/opentelemetry-go/api/metric"
"github.com/open-telemetry/opentelemetry-go/api/stats"
"github.com/open-telemetry/opentelemetry-go/api/tag"
@@ -64,8 +63,6 @@ func main() {
trace.SetError(ctx, true)
log.Log(ctx, "Nice operation!", tag.New("bogons").Int(100))
trace.Active(ctx).SetAttributes(anotherKey.String("yes"))
gauge.Set(ctx, 1)
@@ -76,8 +73,6 @@ func main() {
func(ctx context.Context) error {
trace.Active(ctx).SetAttribute(lemonsKey.String("five"))
log.Logf(ctx, "Format schmormat %d!", 100)
stats.Record(ctx, measureTwo.M(1.3))
return nil

View File

@@ -19,7 +19,6 @@ import (
"net/http"
"github.com/open-telemetry/opentelemetry-go/api/core"
"github.com/open-telemetry/opentelemetry-go/api/log"
"github.com/open-telemetry/opentelemetry-go/api/tag"
"github.com/open-telemetry/opentelemetry-go/api/trace"
"github.com/open-telemetry/opentelemetry-go/plugin/httptrace"
@@ -42,7 +41,7 @@ func main() {
req = req.WithContext(tag.WithMap(req.Context(), tag.NewMap(core.KeyValue{}, tags, core.Mutator{}, nil)))
ctx, span := tracer.Start(
_, span := tracer.Start(
req.Context(),
"hello",
trace.WithAttributes(attrs...),
@@ -50,8 +49,6 @@ func main() {
)
defer span.Finish()
log.Log(ctx, "handling this...")
io.WriteString(w, "Hello, world!\n")
}

View File

@@ -150,18 +150,12 @@ func (ct *clientTracer) wroteRequest(info httptrace.WroteRequestInfo) {
}
func (ct *clientTracer) got100Continue() {
ct.current().Log(ct.Context, "GOT 100 - Continue")
}
func (ct *clientTracer) wait100Continue() {
ct.current().Log(ct.Context, "GOT 100 - Wait")
}
func (ct *clientTracer) got1xxResponse(code int, header textproto.MIMEHeader) error {
ct.current().Log(ct.Context, "GOT 1xx",
HTTPStatus.Int(code),
HTTPHeaderMIME.String(sm2s(header)),
)
return nil
}