| 67 | } |
| 68 | |
| 69 | func (rp *RequestProcessor) ProcessQueryStream( |
| 70 | ctx context.Context, |
| 71 | input *RequestInput, |
| 72 | queryReq proto.Message, |
| 73 | onPage func(proto.Message) error, |
| 74 | ) error { |
| 75 | start := time.Now() |
| 76 | ctx, span := common.StartSpan(ctx, "QueryStream.Handle") |
| 77 | defer span.End() |
| 78 | |
| 79 | project, err := rp.erpc.GetProject(input.ProjectId) |
| 80 | if err != nil { |
| 81 | common.SetTraceSpanError(span, err) |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | method := queryMethodFromProto(queryReq) |
| 86 | networkID := fmt.Sprintf("%s:%s", input.Architecture, input.ChainId) |
| 87 | |
| 88 | span.SetAttributes( |
| 89 | attribute.String("query.method", method), |
| 90 | attribute.String("project.id", input.ProjectId), |
| 91 | attribute.String("network.id", networkID), |
| 92 | ) |
| 93 | |
| 94 | lg := rp.logger.With(). |
| 95 | Str("component", "queryStream"). |
| 96 | Str("projectId", input.ProjectId). |
| 97 | Str("networkId", networkID). |
| 98 | Str("method", method). |
| 99 | Str("clientIP", input.ClientIP). |
| 100 | Logger() |
| 101 | |
| 102 | lg.Info().Msgf("processing query stream request") |
| 103 | |
| 104 | nq := common.NewNormalizedRequestFromJsonRpcRequest( |
| 105 | common.NewJsonRpcRequest(method, []interface{}{}), |
| 106 | ) |
| 107 | nq.SetClientIP(input.ClientIP) |
| 108 | if input.UserAgent != "" { |
| 109 | nq.SetAgentName(input.UserAgent) |
| 110 | } |
| 111 | |
| 112 | user, err := project.AuthenticateConsumer(ctx, nq, method, input.AuthPayload) |
| 113 | if err != nil { |
| 114 | lg.Debug().Err(err).Msgf("query stream authentication failed") |
| 115 | common.SetTraceSpanError(span, err) |
| 116 | return err |
| 117 | } |
| 118 | nq.SetUser(user) |
| 119 | |
| 120 | network, err := project.GetNetwork(ctx, networkID) |
| 121 | if err != nil { |
| 122 | lg.Debug().Err(err).Msgf("failed to resolve network for query stream") |
| 123 | common.SetTraceSpanError(span, err) |
| 124 | return err |
| 125 | } |
| 126 | nq.SetNetwork(network) |