Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

go - Get execution ID for Google Cloud Functions triggered from PubSub event

For Google Cloud Functions triggered from HTTP, it is possible to retrieve the execution id by inspecting the headers of the HTTP request ("Function-Execution-Id") :

package p

import (
    "fmt"
    "net/http"
)

func F(w http.ResponseWriter, r *http.Request) {
    executionID := r.Header.Get("Function-Execution-Id")
    fmt.Println(executionID)
}

However, for GCF triggered by PubSub events, I can't find how to retrieve this execution ID :

package p

import (
    "context"
)

type PubSubMessage struct {
    Data []byte `json:"data"`
}

func F(ctx context.Context, m PubSubMessage) error {
    executionID := "" // ???
    fmt.Println(executionID)
    return nil
}

I have looked into the PubSubMessage (https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage), but it only contains data + an empty attributes map.

I have also checked if execution ID is in the metadata handled by the context. However, from my tests, and the docs (https://godoc.org/cloud.google.com/go/functions/metadata#FromContext), only EventID, Timestamp, EventType and Resource are present.

How can I retrieve the execution id of a GCF function triggered by a PubSub event?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...