-
-
Save dselans/b854c41a1023390eb551bdb9911052ec to your computer and use it in GitHub Desktop.
streamdal_go_instrumentation_example
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
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"math/rand" | |
"time" | |
streamdal "github.com/streamdal/go-sdk" | |
"github.com/streamdal/streamdal/libs/protos/build/go/protos" | |
) | |
func main() { | |
sc, err := streamdal.New(&streamdal.Config{ | |
// Address of the streamdal server | |
ServerURL: "localhost:8082", | |
// Token used for authenticating with the streamdal server | |
ServerToken: "1234", | |
// Identify _this_ application/service ( | |
ServiceName: "billing-svc", | |
ShutdownCtx: context.Background(), | |
}) | |
if err != nil { | |
log.Fatalf("failed to create streamdal client: %v", err) | |
} | |
for { | |
data := getNewEvent() | |
resp := sc.Process(context.Background(), &streamdal.ProcessRequest{ | |
ComponentName: "postgresql", | |
OperationType: streamdal.OperationTypeProducer, | |
OperationName: "inspecting-names", | |
Data: data, | |
}) | |
if resp.Status == protos.ExecStatus_EXEC_STATUS_ERROR { | |
log.Fatal("ran into an error during process: ", resp.StatusMessage) | |
} | |
fmt.Println("processed event: ", string(data)) | |
time.Sleep(100 * time.Millisecond) | |
} | |
} | |
func getNewEvent() []byte { | |
events := []string{ | |
`{"name": "John Doe"}`, | |
`{"name": "Jane Doe"}`, | |
`{"name": "Joe Doe"}`, | |
} | |
return []byte(events[rand.Intn(len(events))]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment