Skip to content

Instantly share code, notes, and snippets.

@dselans
Created January 31, 2024 22:33
Show Gist options
  • Save dselans/b854c41a1023390eb551bdb9911052ec to your computer and use it in GitHub Desktop.
Save dselans/b854c41a1023390eb551bdb9911052ec to your computer and use it in GitHub Desktop.
streamdal_go_instrumentation_example
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