-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# zipkin-api-example | ||
This repository shows you how to use the OpenApi/Swagger definition of | ||
the zipkin-server http api. | ||
|
||
Here's a list of examples: | ||
|
||
* [go](go/README.md) - Shows how to generate a client and upload a sample trace. |
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,12 @@ | ||
## Swagger | ||
|
||
The examples in this directory assume that the zipkin API client has been generated using | ||
[go-swagger](https://github.com/go-swagger/go-swagger) into the `client` directory. | ||
|
||
```bash | ||
# once you've installed swagger, build the client | ||
$ wget https://raw.githubusercontent.com/openzipkin/zipkin-api/master/zipkin2-api.yaml | ||
$ swagger generate client -f zipkin2-api.yaml -A zipkin | ||
# now, you can run one of the examples, such as POSTing a test span | ||
$ DEBUG=1 go run post_sample_trace.go | ||
``` |
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"strconv" | ||
"time" | ||
|
||
httptransport "github.com/go-openapi/runtime/client" | ||
"github.com/go-openapi/strfmt" | ||
"github.com/openzipkin/zipkin-api-example/go/client" | ||
"github.com/openzipkin/zipkin-api-example/go/client/operations" | ||
"github.com/openzipkin/zipkin-api-example/go/models" | ||
) | ||
|
||
func main() { | ||
transport := httptransport.New("localhost:9411", "/api/v2", []string{"http"}) | ||
zipkin := client.New(transport, strfmt.Default) | ||
|
||
id := uint64(rand.New(rand.NewSource(time.Now().UnixNano())).Int63()) | ||
spanID := strconv.FormatUint(id, 16) | ||
timestamp := int64(time.Now().UnixNano() / int64(time.Microsecond)) | ||
span := &models.Span{ | ||
TraceID: spanID, | ||
ID: spanID, | ||
Kind: models.SpanKindSERVER, | ||
Name: "test", | ||
Timestamp: timestamp, | ||
Duration: int64(200000), | ||
LocalEndpoint: &models.Endpoint{ | ||
ServiceName: "testService", | ||
IPV4: "192.228.233.62", | ||
Port: 80, | ||
}, | ||
RemoteEndpoint: &models.Endpoint{ | ||
IPV4: "192.228.233.62", | ||
}, | ||
Tags: map[string]string{ | ||
"http.path": "/api", | ||
}, | ||
} | ||
|
||
resp, err := zipkin.Operations.PostSpans( | ||
operations.NewPostSpansParams().WithSpans(models.ListOfSpans{span}), | ||
) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(string(resp.Error())) | ||
} |