forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename client.Client to client.Info (open-telemetry#4416)
Includes documentation and how it's expected to be used by both providers and consumers. Fixes open-telemetry#4058 Signed-off-by: Juraci Paixão Kröhling <[email protected]>
- Loading branch information
1 parent
db4aa87
commit 7dbf1b8
Showing
3 changed files
with
191 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 client_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
|
||
"go.opentelemetry.io/collector/client" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/model/pdata" | ||
) | ||
|
||
func Example_receiver() { | ||
// Your receiver get a next consumer when it's constructed | ||
var next consumer.Traces | ||
|
||
// You'll convert the incoming data into pipeline data | ||
td := pdata.NewTraces() | ||
|
||
// You probably have a context with client metadata from your listener or | ||
// scraper | ||
ctx := context.Background() | ||
|
||
// Get the client from the context: if it doesn't exist, FromContext will | ||
// create one | ||
cl := client.FromContext(ctx) | ||
|
||
// Extract the client information based on your original context and set it | ||
// to Addr | ||
cl.Addr = &net.IPAddr{ // nolint | ||
IP: net.IPv4(1, 2, 3, 4), | ||
} | ||
|
||
// When you are done, propagate the context down the pipeline to the next | ||
// consumer | ||
next.ConsumeTraces(ctx, td) // nolint | ||
} | ||
|
||
func Example_processor() { | ||
// Your processor or exporter will receive a context, from which you get the | ||
// client information | ||
ctx := context.Background() | ||
cl := client.FromContext(ctx) | ||
|
||
// And use the information from the client as you need | ||
fmt.Println(cl.Addr) | ||
} |