1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-03 14:52:56 +02:00

Remove deadcode, and confusing sampler interface from API (#999)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Bogdan Drutu 2020-07-30 15:53:07 -07:00 committed by GitHub
parent ac3fc6f6fd
commit 4b96967571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 234 deletions

View File

@ -1,54 +0,0 @@
// Copyright The 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 trace
import (
"go.opentelemetry.io/otel/api/kv"
)
const (
alwaysOffSamplerDescription = "AlwaysOffSampler"
)
var alwaysOffSamplerDecision = Decision{Sampled: false}
type alwaysOffSampler struct{}
// ShouldSample implements Sampler interface.
// It always returns a Decision with Sampled value set to false
// and with Attributes set to an empty slice.
func (ns alwaysOffSampler) ShouldSample(
_ SpanContext,
_ bool,
_ ID,
_ string,
_ SpanKind,
_ []kv.KeyValue,
_ []Link,
) Decision {
return alwaysOffSamplerDecision
}
// Description implements Sampler interface.
// It returns the description of this sampler.
func (ns alwaysOffSampler) Description() string {
return alwaysOffSamplerDescription
}
var _ Sampler = alwaysOffSampler{}
func AlwaysOffSampler() Sampler {
return alwaysOffSampler{}
}

View File

@ -1,40 +0,0 @@
// Copyright The 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 trace
import (
"testing"
"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/api/kv"
)
func TestNeverSamperShouldSample(t *testing.T) {
gotD := AlwaysOffSampler().ShouldSample(
SpanContext{}, false, ID{}, "span", SpanKindClient, []kv.KeyValue{}, []Link{})
wantD := Decision{Sampled: false}
if diff := cmp.Diff(wantD, gotD); diff != "" {
t.Errorf("Decision: +got, -want%v", diff)
}
}
func TestAlwaysOffSamplerDescription(t *testing.T) {
gotDesc := AlwaysOffSampler().Description()
wantDesc := alwaysOffSamplerDescription
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
t.Errorf("Description: +got, -want%v", diff)
}
}

View File

@ -1,54 +0,0 @@
// Copyright The 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 trace
import (
"go.opentelemetry.io/otel/api/kv"
)
const (
alwaysOnSamplerDescription = "AlwaysOnSampler"
)
var alwaysOnSamplerDecision = Decision{Sampled: true}
type alwaysOnSampler struct{}
// ShouldSample implements Sampler interface.
// It always returns a Decision with Sampled value set to true
// and with Attributes set to an empty slice.
func (as alwaysOnSampler) ShouldSample(
_ SpanContext,
_ bool,
_ ID,
_ string,
_ SpanKind,
_ []kv.KeyValue,
_ []Link,
) Decision {
return alwaysOnSamplerDecision
}
// Description implements Sampler interface.
// It returns the description of this sampler.
func (as alwaysOnSampler) Description() string {
return alwaysOnSamplerDescription
}
var _ Sampler = alwaysOnSampler{}
func AlwaysOnSampler() Sampler {
return alwaysOnSampler{}
}

View File

@ -1,40 +0,0 @@
// Copyright The 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 trace
import (
"testing"
"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/api/kv"
)
func TestAlwaysOnSamplerShouldSample(t *testing.T) {
gotD := AlwaysOnSampler().ShouldSample(
SpanContext{}, false, ID{}, "span", SpanKindClient, []kv.KeyValue{}, []Link{})
wantD := Decision{Sampled: true}
if diff := cmp.Diff(wantD, gotD); diff != "" {
t.Errorf("Decision: +got, -want%v", diff)
}
}
func TestAlwaysOnSamplerDescription(t *testing.T) {
gotDesc := AlwaysOnSampler().Description()
wantDesc := alwaysOnSamplerDescription
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
t.Errorf("Description: +got, -want%v", diff)
}
}

View File

@ -1,46 +0,0 @@
// Copyright The 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 trace
import "go.opentelemetry.io/otel/api/kv"
type Sampler interface {
// ShouldSample returns a Decision that contains a decision whether to sample
// or not sample the span to be created. Decision is based on a Sampler specific
// algorithm that takes into account one or more input parameters.
ShouldSample(
sc SpanContext,
remote bool,
traceID ID,
spanName string,
spanKind SpanKind,
attributes []kv.KeyValue,
links []Link,
) Decision
// Description returns of the sampler. It contains its name or short description
// and its configured properties.
// For example 'ProbabilitySampler:{0.00001}'
Description() string
}
type Decision struct {
// Sampled is set true if the span should be sampled.
Sampled bool
// Attributes provides insight into Sample r's decision process.
// It could be empty slice or nil if no attributes are recorded by the sampler.
Attributes []kv.KeyValue
}