I'm building a client server to connect with Hyperledger Fabric network using fabric-go-sdk. To use a custom logging system, I get an FabricSDK object using fabsdk.New() then inject it to a Gateway object using gateway.WithSDK function. Check the code below:

    ccpPath := getPath("connection-profile.json", staticPath)
    sdk, err := fabsdk.New(config.FromFile(ccpPath),
        fabsdk.WithLoggerPkg(&FabSDKLoggerProvider{}), // using my custom logging system
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to create a new fabsdk")
    }

    gw, err := gateway.Connect(
        gateway.WithSDK(sdk),
        gateway.WithIdentity(wallet, "admin"),
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
    }

When I run a test, I get an error:

Failed to submit: error registering for TxStatus event: could not create client conn: could not connect to peer0.test.bpl:7051: dialing connection on target [peer0.test.bpl:7051]: connection is in TRANSIENT_FAILURE

The test that I ran is a test to send a transaction using the Gateway object and its Submit method.

When I defined a Gateway object without FabricSDK, it works fine. That is, if I use the code below, the test passes well. However, in this case, I cannot use my custom logging system. (I just want to disable Fabric SDK's logging system.)

    ccpPath := getPath("connection-profile.json", staticPath)
    gw, err := gateway.Connect(
        gateway.WithConfig(config.FromFile(ccpPath)),
        gateway.WithIdentity(wallet, "admin"),
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
    }

According to my investigation, difference between FabricSDK objects initialized by fabsdk.New() and gateway.Connect(gateway.WithConfig()) is that the FabricSDK object that is created by gateway.Connect(gateway.WithConfig()) has the option fabsdk.WithMSPPkg(gw.mspfactory) but the other does not. I try to give the same option to my fabsdk.New() code, I could not find how to do it.

So, my question is:

  • How can I deal with "TRANSIENT_FAILURE" error, or
  • How can I disable the Fabric SDK's default logging system?

Thanks.

1

There are 1 answers

0
James Taylor On BEST ANSWER

I just had exactly the same two questions while writing a little sample CLI to get chaincode metadata

How can I deal with "TRANSIENT_FAILURE" error

In my case, the dialing connection on target [peer0.org1.example.com:7051]: connection is in TRANSIENT_FAILURE error was because I was using the Fabric test network docker environment but I had not set the DISCOVERY_AS_LOCALHOST environment variable. DISCOVERY_AS_LOCALHOST determines whether IP addresses found during service discovery are translated from the docker network to the local host, which is described in the Connection Options documentation for developing applications.

How can I disable the Fabric SDK's default logging system?

I still wanted to see error messages but I was able to change the logging level to get rid of unwanted info messages using logging.SetLevel("", logging.ERROR)

The ccmetadata sample is on GitHub if that's any help