Git Product home page Git Product logo

Comments (9)

arugal avatar arugal commented on July 21, 2024 1

@Saicasm I found that gorm has hooks and maybe we can implement a plugin based on them.

from go2sky.

Saicasm avatar Saicasm commented on July 21, 2024 1

Hi @arugal thanks for the response ,so go2sky doesn't support any database related metrics ?

For now, yes. Here is the list of plugins https://github.com/SkyAPM/go2sky-plugins#go2sky-plugins

Okay, thank you @arugal

from go2sky.

wu-sheng avatar wu-sheng commented on July 21, 2024 1

I don't know what do you mean. Is database showing up on the UI? If so, it must have included in a span.

And about auto instrumentation, yes, I don't think there is a way, according to Google golang team.

from go2sky.

arugal avatar arugal commented on July 21, 2024
package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"strconv"

	"github.com/SkyAPM/go2sky"
	httpPlugin "github.com/SkyAPM/go2sky/plugins/http"
	"github.com/SkyAPM/go2sky/reporter"
	"github.com/gorilla/mux"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	_ "github.com/jinzhu/gorm/dialects/postgres"
)

var db *gorm.DB
var err error

type Booking struct {
	Id      int    `json:"id"`
	User    string `json:"user"`
	Members int    `json:"members"`
}

func homePage(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome to HomePage!")
	fmt.Println("Endpoint Hit: HomePage")
}

func main() {
	
	database, err := gorm.Open("mysql", "user:password@/test?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic("Failed to connect to database!")
	}

	database.AutoMigrate(&Booking{})
	db = database
	re, err := reporter.NewGRPCReporter("localhost:11800")
	if err != nil {
		log.Fatalf("new reporter error %v \n", err)
	}
	defer re.Close()
	// re, err := reporter.NewLogReporter()
	// if err != nil {
	// 	log.Fatalf("new reporter error %v \n", err)
	// }
	// defer re.Close()

	tracer, err := go2sky.NewTracer("go-http-client", go2sky.WithReporter(re))
	if err != nil {
		log.Fatalf("create tracer error %v \n", err)
	}

	sm, err := httpPlugin.NewServerMiddleware(tracer)
	if err != nil {
		log.Fatalf("create server middleware error %v \n", err)
	}
	// span, ctx, err := tracer.CreateLocalSpan(context.Background())
	// go2sky.TraceID(ctx)
	// subSpan, newCtx, err := tracer.CreateLocalSpan(ctx)
	// fmt.Println(newCtx)
	// subSpan.End()
	// span.End()

	log.Println("Starting development server at http://127.0.0.1:10000/")
	log.Println("Quit the server with CONTROL-C.")
	// creates a new instance of a mux router

	myRouter := mux.NewRouter().StrictSlash(true)

	myRouter.HandleFunc("/", homePage)
	myRouter.HandleFunc("/new-booking", createNewBooking).Methods("POST")
	myRouter.HandleFunc("/all-bookings", returnAllBookings)
	myRouter.HandleFunc("/booking/{id}", returnSingleBooking)
	log.Fatal(http.ListenAndServe(":10000", sm(myRouter)))
}
func createNewBooking(w http.ResponseWriter, r *http.Request) {
	// get the body of our POST request
	// return the string response containing the request body
	reqBody, _ := ioutil.ReadAll(r.Body)
	var booking Booking
	json.Unmarshal(reqBody, &booking)
	db.Create(&booking)
	fmt.Println("Endpoint Hit: Creating New Booking")
	json.NewEncoder(w).Encode(booking)
}
func returnAllBookings(w http.ResponseWriter, r *http.Request) {
	bookings := []Booking{}
	db.Find(&bookings)
	fmt.Println("Endpoint Hit: returnAllBookings")
	json.NewEncoder(w).Encode(bookings)
}
func returnSingleBooking(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	key := vars["id"]
	bookings := []Booking{}
	db.Find(&bookings)
	for _, booking := range bookings {
		// string to int
		s, err := strconv.Atoi(key)
		if err == nil {
			if booking.Id == s {
				fmt.Println(booking)
				fmt.Println("Endpoint Hit: Booking No:", key)
				json.NewEncoder(w).Encode(booking)
			}
		}
	}
}

Hi @Saicasm, currently go2sky does not have gorm plugin.

from go2sky.

Saicasm avatar Saicasm commented on July 21, 2024

Hi @arugal thanks for the response ,so go2sky doesn't support any database related metrics ?

from go2sky.

arugal avatar arugal commented on July 21, 2024

Hi @arugal thanks for the response ,so go2sky doesn't support any database related metrics ?

For now, yes. Here is the list of plugins https://github.com/SkyAPM/go2sky-plugins#go2sky-plugins

from go2sky.

wu-sheng avatar wu-sheng commented on July 21, 2024

@Saicasm I think the point is you need to have the exit span, with spanLayer=DATABASE and several specific tag keys.

https://github.com/apache/skywalking/blob/master/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/MultiScopesAnalysisListener.java#L198-L232

from go2sky.

Saicasm avatar Saicasm commented on July 21, 2024

@Saicasm I think the point is you need to have the exit span, with spanLayer=DATABASE and several specific tag keys.

https://github.com/apache/skywalking/blob/master/oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/MultiScopesAnalysisListener.java#L198-L232

@wu-sheng thanks for the info ,i'm able to register database but the traces and other db metrics are not shown and i believe we have it coming up in the go2sky roadmap !?
Also for distributed tracing does it have to be manually instrumented ? Go doesn't support auto instrumentation ?

from go2sky.

arugal avatar arugal commented on July 21, 2024

Discuss in new issue #78

from go2sky.

Related Issues (20)

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.