Now I have a Golang Application deployed on GAE, with stackdriver trace.
About stackdriver Trace, to get custom span data, I did set up on my code, like
exporter, err := stackdriver.NewExporter(stackdriver.Options{
ProjectID: os.Getenv("GOOGLE_CLOUD_PROJECT"),
})
if err != nil {
log.Fatal(err)
}
trace.RegisterExporter(exporter)
client := &http.Client{
Transport: &ochttp.Transport{
// Use Google Cloud propagation format.
Propagation: &propagation.HTTPFormat{},
},
}
ref. https://cloud.google.com/trace/docs/setup/go
On GAE, I succeed in viewing trace on my GCP console.
but, I DON'T want to trace these log on my local developing environment (I'm using docker).currently, I try to run my application on docker, nil pointer panic shows up on Span.Export() which may be called from Span.End().
So, I wonder if someone knows the way to DISABLE stackdriver trace on specific environment (with my case, on docker).
Otherwise, should I check condition of trace configuration, like as below ?
if trace.projectId != "" {
ctx := reque.Context()
_, span := trace.StartSpan(ctx,"Span blahblah")
defer span.End()
}
There is no point for Google in adding an extra logic like you need into the Trace code, the GAE apps are instrumented with, in order to disable that Trace code when the GAE App is executed somewhere in a third party environment like Docker on-prem. Most likely an answer to the question is "No, there is no magic config for that". Hence it is up-to-you how to sort this out.
As a general idea: following up an approach with [NoopExporter] offered by Emile Pels and having admitted the fact we can't get rid of the Trace code with "magic config", if I developed my app in Python I'd considered using decorator as a wrapper to bring piece of intelligence into the Trace calls, or redefining them as mock functions. It seems Golang does not have direct analog of Python decorators but this functionality could be implemented somehow. This is being discussed in the Internet, for example here:
Go Decorator Function Pattern
Redefine function so that it references its own self
Related
I've checked the documentation but it does not explain the use of setting test mode for gin
gin.SetMode(gin.TestMode)
What is this test mode provided for? I do not see any difference when setting & not setting this mode in my tests.
The flag gin.DebugMode is used to control the output of gin.IsDebugging(), which adds some additional log output and changes the HTML renderer to the debug struct HTMLDebug.
The gin.TestMode is used in Gin's own unit tests to toggle the debug mode (and the additional logging) on and off, and the usage of the debug HTML renderer.
Other than that, it doesn't have other uses (source).
However, the flag can be controlled with the environment variable GIN_MODE=test. Then, since Mode() is exported, you can use it in application code to, for example, declare testing routes. This might have some merit if you plan to run an E2E test suite, or some other integration test:
r := gin.New()
if gin.Mode() == gin.TestMode {
r.GET("/test", func(c *gin.Context) {
c.String(418, "I don't exist in production")
})
}
I'm testing this small code fragment using miniredis mock for Redis. repository.client is a functioning mock (used for other tests) that returns a Redis client.
err := repository.client.Publish(ctx, "UPDATE", "MESSAGE").Err()
if err != nil {
log.fatal(err.Error())
}
When I run the test it logs me the following error:
ERR unknown command `publish`, with args beginning with: `UPDATES`, `MESSAGE`,
I'm confused by the fact that miniredis should implement pub-sub functionalities. Any clue of what is the issue?
After researching on owner's repository I found out that the issue was related to the imported version. In online articles, it is normally cited the import github.com/alicebob/miniredis, but it doesn't have implemented pub/sub functionalities. To make them work it is important to import V2:
github.com/alicebob/miniredis/v2
Source: https://github.com/alicebob/miniredis/issues/157
I have a Go Application that needs to consume a GraphQL service, now the documentation of graphQL is more oriented to the GraphQL server and not as a client. How can I do that?
I checked this example but some things are not clear to me:
Should I have a Resolve function to each field that I am going to retrieve?
Should I have defined the variable 'fields' with the data structure that I am expecting?
Where can I find a very simple example of a GraphQL client in Golang?
You should check this project: https://github.com/machinebox/graphql .
If you don't want to use an external library inside in your project, you could look the code and see how can you implement a simple client.
One of the module that I would recommend is shurcool
client = graphql.NewClient("http://<<graphqlEndpoint>>", nil)
err := client.Query(context.Background(), &query, nil)
if err != nil {
// Handle error.
}
fmt.Println(query.Me.Name)
I used to set up a Fabric network and deployed a fabric network and basic application using a Fabric and Fabric GoLang SDK. I'm able to do the query and write to the chain.
Is there any way to retrieve the Block Info? Like block height and current hash?
+ I'm unable to find out a documentation for GoLang Fabric SDK.
I followed following code and tutorial,
Fabric Basic App - Tutorial
https://chainhero.io/2017/07/tutorial-build-blockchain-app/
Fabric Basic App using GoLang SDK - Code
https://github.com/chainHero/heroes-service/
GoLang SDK - Official SDK
https://github.com/hyperledger/fabric-sdk-go
In general, the sdk will provide the basic method such you said GetBlockInfo,I have search for the GoLang SDK, it can not be found. While Java sdk provide this such method reference this java test .
Another way to use these method(you must know a little fabric source code), in fact these method are included in the system chaincode, you could invoke the system chancode just like you invoke the normal chaincode.
A example is following:
from the go sdk test ,you could see this,
response, err := chClient.Query(chclient.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
just change the params
response, err := chClient.Query(chclient.Request{ChaincodeID: "qscc", Fcn: "invoke", Args: integration.ExampleCCQueryArgs("GetChainInfo")})
qscc is a system chancode,you could download the fabric source code,and from qscc file,you could see(it provide many invoke service):
GetChainInfo string = "GetChainInfo"
GetBlockByNumber string = "GetBlockByNumber"
GetBlockByHash string = "GetBlockByHash"
GetTransactionByID string = "GetTransactionByID"
GetBlockByTxID string = "GetBlockByTxID"
Go sdk(fabric-sdk-go/pkg/client/ledger) provides several methods for getting information about blockchain. For example:
...
client, err := ledger.New(channelContext)
block, err := client.QueryBlockByHash(blockHash)
block, err = client.QueryBlock(blockNumber)
The Go SDK now includes methods for querying block information. These methods are contained within the ledger client package.
You can see an example in the ledger client integration test.
Background
I have a java server that is making an RPC call to a go server. The java rpc client and go rpc server are instrumented with lightstep. Everything about the trace looks normal except for where in the lightstep UI, the go rpc server span is placed.
The java span has ts 1493929521325 which is right before the request is sent to the go server. The go rpc server has 2 timestamps: 1493929521326 is when it received the request and started the span, 1493929521336 is after it responded and finished the span.
Problem
I would expect the UI to have the go span horizontally to the immediate right of the java span. Instead, it is far to the right.
The only possible cause I can think of is an incompatibility between v0.10.1 which java code is using and v0.9.1 which go is using. Is this a possibility? Do you have any thoughts on a possible cause?
The go code is essentially:
import (
lightstep "github.com/lightstep/lightstep-tracer-go"
opentracing "github.com/opentracing/opentracing-go"
)
tracer := lightstep.NewTracer(lightstep.Options{
AccessToken: ls.AccessToken,
Collector: lightstep.Endpoint{ls.Host, ls.Port, true},
Tags: map[string]interface{}{lightstep.ComponentNameKey: component},
})
spanContext, err := tracer.Extract(opentracing.TextMap, opentracing.TextMapCarrier(req.GetLightstepData()))
span = tracer.StartSpan(
endpoint,
opentracing.ChildOf(spanContext))
}
// handle the request
span.Finish()
[Disclaimer: I work at LightStep]
Sorry you're having trouble getting Java and Go to play well together. I suspect this is caused by time-correction being enabled in Java but not being used in Go.
You can disable time correction in Java using the withClockSkewCorrection(boolean clockCorrection)
option to turn off clockCorrection when passing in options to the LightStep tracer
Here is the updated README and a link to the option code
If you contact us via the [Support] button in LightStep, we should be able to get you sorted out. Please send us a note so that we can confirm that this is solved for you.
We'll start monitoring SO more carefully so that we catch these things earlier.
Thanks and happy tracing!
Will