GithubHelp home page GithubHelp logo

sample-golang-app's Introduction

Bookstore REST API using Gin and Gorm

Read this article on understand how to build a sample golang app using Gin and Gorm.

Note:

If you are using the without-instrumentation branch to instrument the app following the blog post present here, after you are done with making the necessary changes in the main.go file, run:

go mod tidy

to download the required packages and populate the go.sum file.

To run and configure app to send data to SigNoz:

For SigNoz Cloud:

SERVICE_NAME=goApp INSECURE_MODE=false OTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=<SIGNOZ-INGESTION-TOKEN> OTEL_EXPORTER_OTLP_ENDPOINT=ingest.{region}.signoz.cloud:443 go run main.go
  • Update <SIGNOZ-INGESTION-TOKEN> with the ingestion token provided by SigNoz
  • Update ingest.{region}.signoz.cloud:443 with the ingestion endpoint of your region. Refer to the table below for the same.
Region Endpoint
US ingest.us.signoz.cloud:443
IN ingest.in.signoz.cloud:443
EU ingest.eu.signoz.cloud:443

For SigNoz OSS:

SERVICE_NAME=goApp INSECURE_MODE=true OTEL_EXPORTER_OTLP_ENDPOINT=<IP of SigNoz backend>:4317 go run main.go
  • <IP of SigNoz backend:4317> should be without http/https scheme. Eg localhost:4317.

This runs the gin application at port 8090. Try accessing API at http://localhost:8090/books

Below are the apis available to play around. The API calls will generate telemetry data which will be sent to SigNoz which can be viewed at <IP of SigNoz backend>:3000

GET    /books                    
GET    /books/:id               
POST   /books                    
PATCH  /books/:id                
DELETE /books/:id                

The OpenTelemetry registry is the best place to discover instrumentation packages. It will include packages outside of this project.

The following instrumentation packages are provided for popular Go packages and use-cases.

Instrumentation Package Metrics Traces
github.com/astaxie/beego
github.com/aws/aws-sdk-go-v2
github.com/bradfitz/gomemcache
github.com/emicklei/go-restful
github.com/gin-gonic/gin
github.com/go-kit/kit
github.com/gocql/gocql
github.com/gorilla/mux
github.com/labstack/echo
github.com/Shopify/sarama
go.mongodb.org/mongo-driver
google.golang.org/grpc
gopkg.in/macaron.v1
host
net/http
net/http/httptrace
runtime

Follow Opentelemetry docs for examples on latest otel releases: Opentelemetry-go

sample-golang-app's People

Contributors

ankitnayan avatar makeavish avatar nityanandagohain avatar pranay01 avatar prashant-shahi avatar srikanthccv avatar zriyansh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sample-golang-app's Issues

Parent traceID not propogating to REST calls using otelgin.Middleware

HI

Trying sample Application using Gin and otelgin.Middleware() to stich chain of REST API calls. Below is the scenario tried. (which is mentioned in https://signoz.io/blog/opentelemetry-gin/)

  1. Make rest call to Books Application
  2. Books applications make call to Stores Applications to get all books from All stores
  3. Store applications just return empty.

image

Actually Books API call and Store Api calls' should be linked. But it not happening and both calls having different TraceID.

Note : Same tried with Mux it is working. Signoz used for view traces

Screenshots:
Books Application:
image

Store Application:
image

Example code available in https://github.com/Connect2naga/Examples/tree/main/Standalone

Please correct me if any thing missed or need to change the configuration.

Outdated dependencies

The API provided by the upstream opentelemetry repos appears to have changed, so this project can no longer be referenced as an example when integrating opentelemetry and SigNoz into an existing Go application.

It would be very helpful if this application could be updated to use the latest versions of all the opentelemetry dependencies.

app not working for updated versions

here's the go.mod file - have updated opentelemetry packages only and made go v1.17 to 1.20

module github.com/SigNoz/sample-golang-app

go 1.20

require (
	github.com/gin-gonic/gin v1.9.1
	github.com/uptrace/opentelemetry-go-extra/otelgorm v0.2.2
	go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.42.0
	go.opentelemetry.io/otel v1.16.0
	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
	go.opentelemetry.io/otel/sdk v1.16.0
	go.opentelemetry.io/otel/trace v1.16.0
	google.golang.org/grpc v1.55.0
	gorm.io/driver/sqlite v1.3.2
	gorm.io/gorm v1.25.1
)

require (
	github.com/bytedance/sonic v1.9.1 // indirect
	github.com/cenkalti/backoff/v4 v4.2.1 // indirect
	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
	github.com/gabriel-vasile/mimetype v1.4.2 // indirect
	github.com/gin-contrib/sse v0.1.0 // indirect
	github.com/go-logr/logr v1.2.4 // indirect
	github.com/go-logr/stdr v1.2.2 // indirect
	github.com/go-playground/locales v0.14.1 // indirect
	github.com/go-playground/universal-translator v0.18.1 // indirect
	github.com/go-playground/validator/v10 v10.14.0 // indirect
	github.com/goccy/go-json v0.10.2 // indirect
	github.com/golang/protobuf v1.5.3 // indirect
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
	github.com/jinzhu/inflection v1.0.0 // indirect
	github.com/jinzhu/now v1.1.5 // indirect
	github.com/json-iterator/go v1.1.12 // indirect
	github.com/klauspost/cpuid/v2 v2.2.4 // indirect
	github.com/kr/pretty v0.3.0 // indirect
	github.com/leodido/go-urn v1.2.4 // indirect
	github.com/mattn/go-isatty v0.0.19 // indirect
	github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.2 // indirect
	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
	github.com/rogpeppe/go-internal v1.9.0 // indirect
	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
	github.com/ugorji/go/codec v1.2.11 // indirect
	github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2 // indirect
	go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
	go.opentelemetry.io/otel/metric v1.16.0 // indirect
	go.opentelemetry.io/proto/otlp v0.19.0 // indirect
	golang.org/x/arch v0.3.0 // indirect
	golang.org/x/crypto v0.9.0 // indirect
	golang.org/x/net v0.10.0 // indirect
	golang.org/x/sys v0.8.0 // indirect
	golang.org/x/text v0.9.0 // indirect
	google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
	google.golang.org/protobuf v1.30.0 // indirect
	gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
)

here's the error

priyanshkhodiyar@Priyanshs-MacBook-Air sample-golang-app % SERVICE_NAME=goApp INSECURE_MODE=true OTEL_EXPORTER_OTLP_ENDPOINT=stagingapp.signoz.io:4317 go run main.go

# gorm.io/driver/sqlite
../../../go/pkg/mod/gorm.io/driver/[email protected]/sqlite.go:100:22: invalid operation: limit.Limit > 0 (mismatched types *int and untyped int)
../../../go/pkg/mod/gorm.io/driver/[email protected]/sqlite.go:101:24: invalid operation: limit.Limit <= 0 (mismatched types *int and untyped int)
../../../go/pkg/mod/gorm.io/driver/[email protected]/sqlite.go:102:21: cannot use -1 (untyped int constant) as *int value in assignment
../../../go/pkg/mod/gorm.io/driver/[email protected]/sqlite.go:105:39: cannot use limit.Limit (variable of type *int) as int value in argument to strconv.Itoa

cc - @makeavish @prashant-shahi

blog followed - https://signoz.io/opentelemetry/go/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.